开发者

What is the importance of IMetadataExchange in 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/"开发者_StackOverflow/>
          </baseAddresses>
        </host>
        <endpoint address="" binding="basicHttpBinding" contract="WCFService.IMathOperations"/>
      </service>
    </services>
  </system.serviceModel>
</configuration>


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.


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.


The difference is:

<serviceMetadata httpGetEnabled="true"/>

allows you to retrieve metadata using the HTTP protocol.

<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />

allows you to retrieve metadata using the ws-metadata protocol.

Just <serviceMetadata httpGetEnabled="true"/> works, but not all clients can call you (because they can't retrieve metadata to create a proxy).

The standard is to publish both.

See also ServiceMetadataBehavior Class (MSDN).


Without IMetadataExchange, a WCF service exposes the metadata information to the client, but WCF does not guarantee to expose the metadata because WCF default features to exposing the metadata to the client.

Exposing the metadata is done in a well-standardized way through IMetadataExchange. The IMetadataExchange interface follows the industry standard.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜