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 service.
In
the below example you can find that WCF service is self hosted using console
application.
ServiceHost
objServiceHost = new ServiceHost(typeof(AdaptService),
new Uri[] { new Uri("http://localhost:9080/") }); ServiceMetadataBehavior
objMetadataBehaviour = new ServiceMetadataBehavior(); objMetadataBehaviour.HttpGetEnabled
= true; objServiceHost.Description.Behaviors.Add(objMetadataBehaviour); objServiceHost.AddServiceEndpoint(typeof(IAdaptService),
new WSHttpBinding(),
"http://localhost:9080/"); objServiceHost.AddServiceEndpoint(typeof(IMetadataExchange),
new WSHttpBinding(),
"MEX"); objServiceHost.Open(); Console.WriteLine("The service is running."); Console.WriteLine("Please <Enter> to terminate the
service."); Console.ReadLine(); objServiceHost.Close();
|