Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the importance of IMetadataExchange in WCF?

Tags:

wcf

What is 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. How is it 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/"/>
          </baseAddresses>
        </host>
        <endpoint address="" binding="basicHttpBinding" contract="WCFService.IMathOperations"/>
      </service>
    </services>
  </system.serviceModel>
</configuration>
like image 206
Embedd_0913 Avatar asked Oct 22 '09 08:10

Embedd_0913


2 Answers

ArsenMkrt has the formal answer. Put more simply:

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

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.

like image 93
Shiraz Bhaiji Avatar answered Oct 03 '22 01:10

Shiraz Bhaiji


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.

like image 33
Arsen Mkrtchyan Avatar answered Oct 03 '22 01:10

Arsen Mkrtchyan