Lets discuss about how the metadata is exchanged with client in WCF.
There are two ways to exchange metadata with client.
1> MexHttpBinding
2> WSDL
1> Enabling MexHttpBinding:
We can have the metadata exchanged through mexHttpBinding by adding endpoint in our config file like:
- <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
2> Enabling WSDL
In the Service Behaviors set httpGetEnabled="true"
- <serviceMetadata httpGetEnabled="false"/>
If both are added default will be WSDL
Example:
Lets assume we have simple service with IService as contract and web.config of service model looks like this
- <system.serviceModel>
- <services>
- <service name="WcfService.Service" behaviorConfiguration="WcfService1.Service1Behavior">
- <endpoint address="" binding="basicHttpBinding" contract="WcfService.IService">
- <identity>
- <dns value="localhost"/>
- </identity>
- </endpoint>
- <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
- </service>
- </services>
- <behaviors>
- <serviceBehaviors>
- <behavior name="WcfService1.Service1Behavior">
- <serviceMetadata httpGetEnabled="true"/>
- <serviceDebug includeExceptionDetailInFaults="false"/>
- </behavior>
- </serviceBehaviors>
- </behaviors>
- </system.serviceModel>
Since we have enabled both ( mex and wsdl ) preference will be always given to WSDL
On browsing the service:
Now we can see metadata is exchanged through WSDL when we add reference of this service to any project.
Disabling WSDL
By simply setting httpGetEnabled=false in Service behavior we can disable WSDl
On browsing service after disabling WSDL
Now we can see that metadata is exchanged with MexHttpBinding.
May 24, 2013 at 8:19 am
Nice Work Dude…
May 27, 2013 at 10:08 am
Very Good.
June 2, 2013 at 4:27 am
Odilla, aadru neevu bardiddira andre channage erutte bidi, 🙂
June 5, 2013 at 9:30 am
Nice & Informative….When should we use mexhttpbinding and any specific code changes required while consuming the service at client side ?
July 24, 2014 at 6:33 am
Wov Excellent
September 12, 2015 at 5:32 am
Nice man ….thanks