To make any WCF service as active that service most be hosted with in a runtime environment which creates the service and controls the life time of the service
This makes easy to debug and trace the application
IIS hosted services will support only “ Http” transport and doesn’t support other transport like Tcp etc.
This is the new mechanism available with windows vista., windows7, windows 2008 server operation system. This is not supported in windows Xp Microsoft introduced this mechanism with IIS 6.0 version (with windows Xp we have IIS 5.0 version) To work with first two hosting we should know about service host class and URI class. These 2 classes are available in system service model namespace.
This class is used to set the required properties for a service, to host the service.
Abort () Close () Open () Add service end point (implemented contract (address) class, binding contract); Abort():- This method is used to terminate the service Close():- This method is used to close the service Open():- This method is used to start a service. Add service Endpoint, (, , ) :- This method is used to add the required end point to the service
Create a new console application with the name example 6 Add a new class with the name IEMP tails.cs change the class to interface in IE details.cs Add reference to system. Service mode namespace Using system data; Using system. Service model; Namespace Example6 { [service contract] interface IEmp details { [operation contract] data table get deptdata(int D); } } create a new class file with the name cls empi .cs & write the following code. using system.data; using system.data.sqlclient; namespace example6 { public class cls emp Details : IE mp Details } Public Data Table Get Deptdata (int D) { sqlconnection con=new sql connection (----); string S = “Select * from emp Details where Deptno=”+D; sqldata Adpater da = new sqldataadapter (s.con); dataset Ds=new Dataset(); (DS, “Emp”); return ds. Tables[0]; } } } Change the program.cs file name to cls sample.cs and write the following code. using system. ServiceModel; Namespace Example6 { Class cls sample { Static voidMain() { vri obju = new uri (“net.tcp://localhost:9100/”); service host objs = new serviceHost (type of (cls emp Details), obju); Objs.open(); c.WL (“service started and running”); C WL (“press any key to terminate-----“); Console. Readline(); Objs. Close(); } } } To mention the end point for the service add app.config file into the application. Steps:- Go to selection Explorer Select the solution click with right mouse button click on add click on new item select the template application configuration fileclick on add write the following code. <xml version = “1.0” encoding = “utf – 8”?> <configuration> <system.servicemodel/> <services> <service name = “Example6.Cls Emp Details”> <endpoint address = “Example6. Cls Emp details” Binding = “net TCP Binding” Contract = “Example6. IEmp details”/> </service> </services> </system.ServiceModel> </configuration> Creating client component to consume the service costed using console application Client Design Create a new windows ohms application Design the form Add reference the service hosted using consol applications. Steps to add reference Go to solution explorer select the solution click with right mouse button click on add service reference type the “net TCP://local host:9100/” click on go button we find the service class name “Cls empdetails” change the reference to me to SRI click on Add, this will create proxy impotent at client side (Note:- Before adding this reference, the service hosted in console application i.e., example 6 should be running otherwise. We can’t add the reference and can’t consume the service) à write the following code. Private void btnsubmit click(-----) { SRI.Empdetails client obj1 = new sRI.Emp Details client(); DGV sample. Datasource = bj1. Getdeptdata (convert to Int32 (txtdeptno. Text)); } àRun the application & click. This client will work a long as the service component created at console application is running. If can closeness.
You liked the article?
Like: 0
Vote for difficulty
Current difficulty (Avg): Medium
TekSlate is the best online training provider in delivering world-class IT skills to individuals and corporates from all parts of the globe. We are proven experts in accumulating every need of an IT skills upgrade aspirant and have delivered excellent services. We aim to bring you all the essentials to learn and master new technologies in the market with our articles, blogs, and videos. Build your career success with us, enhancing most in-demand skills in the market.