We will use Service Behavior to publish the metadata using HTTP-GET. This can be configures either administratively or programmatically. Http and Https can expose by appending "?wsdl" to the end of the service address. For example service address is http://localhost:9090/MyCalulatorService ,HTTP-Get metadata address is given by http://localhost:9090/MyCalulatorService?wsdl.
Administrative
(Configuration file):
In the below mention configuration information, you can find the behavior section in the ServiceBehavior. You can expose the metadata using ServiceMetadata node with httpGetEnable='True'.
<system.serviceModel>
<services>
<service behaviorConfiguration="Service Behavior" name="MyService">
<endpoint address="http://localhost/IISHostedService/MyService.svc"
binding="wsHttpBinding" contract="IMyService">
<identity>
<dns value="localhost"/>
</identity>
</endpoint>
</service>
</services>
<behaviors>
<service Behaviors>
<behavior name="Service Behavior">
<!-Setting httpGetEnabled you can publish the metadata -->
<service Metadata httpGetEnabled="true"/>
</behavior>
</service Behaviors>
</behaviors> system.serviceModel>Programming Model:
//Create a URI to serve as the base address
Uri httpUrl = new Uri("http://localhost:8090/MyService/SimpleCalculator");
//Create ServiceHost
ServiceHost host = new
ServiceHost(typeof(MyCalculatorService.SimpleCalculator), httpUrl);
//Add a service endpoint
host.AddServiceEndpoint
(typeof(MyCalculatorService.ISimpleCalculator), new WSHttpBinding(), "");
//Enable metadata exchange
ServiceMetadataBehavior smb = new ServiceMetadataBehavior();
//Enable metadata exchange using HTTP-GET
smb.HttpGetEnabled = true;
host.Description.Behaviors.Add(smb);
//Start the Service
host.Open();
Console.WriteLine("Service is host at " + DateTime.Now.ToString());
Console.WriteLine("Host is running... Press key to stop");
Console.ReadLine();
No comments:
Post a Comment