.NET > WCF >> ServiceHost Views : 2389
Rate This Article :

ServiceHost

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();

About Author
Manoj
Total Posts 7
For Artile
Comment this article
Name*
Email Address* (Will not be shown on this website.)
Comments*
Enter Image Text*
   
View All Comments
  Privacy   Terms Of Use   Advertise With Us   Contact Us
© 2016 Developerin.Net. All rights reserved.
Trademarks and Article Images mentioned in this site may belongs to Microsoft and other respective trademark owners.
Articles, Tutorials and all other content offered here is for educational purpose only and its author copyrights.