Click here to hide categories Click here to show left categories

User: Home          welcome : Guest          Log In / Register here     




WCF Interview Question - Method to perform Self-Hosting in WCF?

Answer:
 

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 " + DateTime.Now.ToString());          
Console.WriteLine("Host is running... Press <Enter> key to stop");           
Console.ReadLine();

Please click here to see more WCF interview questions

Regards,

Visit Authors blog for more WCF interview questions

Share this article   |    Print    |    Article read by 3673 times
Author:
Shivprasad koirala Koirala
I am a Microsoft MVP for ASP/ASP.NET and currently a CEO of a small E-learning company in India. We are very much active in making training videos , writing books and corporate trainings. Do visit my site http://www.questpond.com for .NET, C# , design pattern , WCF , Silverlight , LINQ , ASP.NET , ADO.NET , Sharepoint , UML , SQL Server training and Interview questions and answers
Related Articles: No related article
Related Interview Questions: No related interview question