Wednesday, 20 May 2015

Exchanging metadata in WCF

There are two ways to exchange metadata with client.
1> MexHttpBinding 

2> WSDL :  In the Service Behaviors set httpGetEnabled="true"

Configuration part that affect metadata  :
ServiceMetadata behaviour : This behaviour controls whether metadata is created for the service.When this behaviour is used, the service is scanned, and metadata is created for the service’s contracts.
If the behaviour is not used, no metadata will be created for the service, and you will not be able to create MEX endpoints.

HttpGetEnabled flag : This flag defines whether the metadata will be accessible by an http get request. If this attribute is set to true, then a default url will be created for the metadata (usually the service’s address with the suffix of  ‘?wsdl’). The url will lead you to a WSDL file containing the description of the service operations.
If you do not set this attribute to true, you will not be able to access the metadata using http get requests

MEX endpoint : MEX endpoints are special endpoints that allow clients to receive the service’s metadata by using SOAP messages instead of http get requests. You can create MEX endpoint that can be accessed through http, https, tcp, and even named pipes.

So what is the difference between MEX and WSDL?

MEX and WSDL both output the same thing – a web service description language (WSDL) document, only MEX does it by getting a SOAP message over some transport (http, tcp, named pipes) and returning one message with all the parts, while the WSDL urls use http get requests and require sending several requests to get all the parts.

<system.serviceModel>
      <services>
        <service name="WcfService.Service" behaviorConfiguration="WcfService1.Service1Behavior">
          <endpoint address="" binding="basicHttpBinding" contract="WcfService.IService">          
          </endpoint>
          <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
        </service>
      </services>
      <behaviors>
        <serviceBehaviors>
          <behavior name="WcfService1.Service1Behavior">
            <serviceMetadata httpGetEnabled="true"/>        
          </behavior>
        </serviceBehaviors>
      </behaviors>
</system.serviceModel>

Related Post :

Different-option-of-hosting-wcf-service
Binding-in-wcf-choosing-right-wcf
Exchanging-metadata-in-wcf
Some-interesting-facts-about-data-contract
Knowntype-attribute-in-wcf
Associating-knowntype-in-wcf
Message-contract-in-wcf
Exception-handling-in-wcf
Exception Handling in WCF - SOAP Fault in WCF
Exception Handling in WCF - Unhandled Exception in WCF
Exception Handling in WCF - Creating and Throwing Strongly Typed SOAP Fault

No comments:

Post a Comment