Saturday, 4 May 2013

Service Host | WCF Tutorial pdf

Service Host object is in the process of hosting the WCF service and registering endpoints. It loads the service configuration endpoints, apply the settings and start the listeners to handle the incoming request. System.ServiceModel.ServiceHost namespace hold this object. This object is created while self hosting the WCF ser vice.
In the below example you can find that WCF ser vice is self hosted using console application.
//Creating uri for the hosting the service
Uri uri = new Uri("http://localhost/CategoryService");
//Creating the host object for MathService
 ServiceHost host = new ServiceHost(typeof(CategoryService), uri);
//Adding endpoint to the Host object
 host.AddServiceEndpoint(typeof(ICategoryService),new WSHttpBinding(), uri);
 host.Open(); //Hosting the Service
 Console.WriteLine("Waiting for client invocations");
 Console.ReadLine();
 host.Close();

No comments: