C#
//Create a host's base addressUri baseaddress =NewUri ("Http://localhost:8080/User");//Create a hostusing(ServiceHost host =NewServiceHost (typeof(User), baseaddress)) {host.} AddServiceEndpoint (typeof(Iuser),NewWshttpbinding (),""); //set the Httpgetenabled property to TrueServiceMetadataBehavior SMB =NewServiceMetadataBehavior (); Smb. Httpgetenabled=true; //add behavior to behaviorshost. DESCRIPTION.BEHAVIORS.ADD (SMB); //Open Hosthost. Open (); Console.WriteLine ("http snooping in WCF started ...."); Console.ReadLine (); Host. Close ();}
App.
<?XML version= "1.0" encoding= "Utf-8"?><Configuration> <System.ServiceModel> <Services> <Servicename= "Wcflibrary.user"> <Host> <baseaddresses> <Addbaseaddress= "Http://localhost:8080/User"/> </baseaddresses> </Host> <EndpointAddress=""binding= "Wshttpbinding"Contract= "Wcflibrary.iuser"></Endpoint> </Service> </Services> <Behaviors> <servicebehaviors> <Behavior> <Servicemetadatahttpgetenabled= "True"/> <ServicedebugIncludeexceptiondetailinfaults= "False"/> </Behavior> </servicebehaviors> </Behaviors> </System.ServiceModel></Configuration>
Public Partial classmainform:form{ServiceHost host; PublicMainForm () {InitializeComponent (); } Private voidMainform_load (Objectsender, EventArgs e) {Host=NewServiceHost (typeof(User)); //Open Hosthost. Open (); This. Label1. Text ="http snooping in WCF started ...."; } Private voidMainform_formclosed (Objectsender, Formclosedeventargs e) {host.} Close (); }}
In WCF, the ServiceHost class is created through C # code or the app. config configuration file