tags:

views:

86

answers:

2

Hi All,

Can anyone please explain me the use and importance of IMetadataExchange in WCF ?

I have the following app.config file in which i don't use IMetadataExchange endpoint but i am still able to create my proxy client.I have read that if i don't use IMetadataExchange endpoint, AddServiceReference will not work because my service does not expose the metadata. My question is, how it's working without exposing IMetadataExchange endpoint?

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.serviceModel>    
    <behaviors>
      <serviceBehaviors>
        <behavior name="metaDataBehavior">
          <serviceMetadata httpGetEnabled="true"/>
        </behavior>
      </serviceBehaviors>
    </behaviors>

    <services>
           <service name ="WCFService.Services" behaviorConfiguration="metaDataBehavior">
        <host>
          <baseAddresses>            
            <add baseAddress="http://localhost:8090/Services/"/&gt;
          </baseAddresses>
        </host>       
        <endpoint address="" binding="basicHttpBinding" contract="WCFService.IMathOperations"/> 
      </service>      
    </services>
  </system.serviceModel>
</configuration>
+3  A: 

IMetadataExchange Interface Exposes methods used to return metadata about a service. When programming Windows Communication Foundation (WCF) services, it is useful to publish metadata about the service. For example, metadata can be a Web Services Description Language (WSDL) document that describes all of the methods and data types employed by a service. Returning metadata about an WCF service allows consumers of a service to easily create clients for the service.

ArsenMkrt
+2  A: 

ArsenMkrt has the formal answer. Put more simply:

  • If you don't have it, add service reference will not work
  • You should delete it from production servers, so that a hacker cannot do add service reference

EDIT

To answer your question more specifically, you have this line on your service:

       <service name ="WCFService.Services" behaviorConfiguration="metaDataBehavior">

Which points to this configuration

    <behavior name="metaDataBehavior">
      <serviceMetadata httpGetEnabled="true"/>
    </behavior>

This may be why it still works, although I thought that you needed to specify the MEX endpoint.

Shiraz Bhaiji
+1 exactly - no metadata -> no way to discover what the service offers, in that case, you'll need a "pre-made" proxy client as code or something else to connect to the service
marc_s