WCF Interview Question - How do you do Self-Hosting?

The following steps are followed to do Self-hosting.

Step1: //Create a URI to serve as the base address
// Address as well binding
Uri httpUrl = new Uri(http://localhost:8010/MyService/HelloWorld);

Step2: //Create ServiceHost
ServiceHost host = new ServiceHost(typeof(ClassLibrary1.HelloWorldService),httpUrl);

Step3: //Add a service endpoint
host.AddServiceEndpoint(typeof(ClassLibrary1.IHelloWorldService) , new WSHttpBinding(), "");

Step4: //Enable metadata exchange
ServiceMetadataBehavior smb = new ServiceMetadataBehavior();
smb.HttpGetEnabled = true;
host.Description.Behaviors.Add(smb);

Step5: //Start the Service
host.Open();
Step6:
Console.WriteLine("Service is host at Time: " + DateTime.Now.ToString());
Console.WriteLine("Service Host is running... Press any key to stop");
Console.ReadLine();

Comments

Popular posts from this blog

SharePoint 2007 - Simple Task Dashboard

MERGE transformation in SSIS