C# WCF发布服务的元数据的方式

发布服务元数据的方式有两种:一是基于HTTP-GET协议提供元数据,它是一种绝大多数平台都能支持的简单text-based协议;另一种是元数据交换终结点。

1.基于HTTP-GET协议

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <system.serviceModel>
    <services>
      <service name="HelloWCFService.HelloWCFService" behaviorConfiguration="metaExchange">
        <host>
          <baseAddresses>
            <add baseAddress="http://localhost:8000/MyService"/>
          </baseAddresses>
        </host>
        <endpoint address="HelloWCFService" binding="wsHttpBinding" contract="HelloWCFService.IHelloWCFService"/>
        <!--<endpoint address="metaExchange" binding="mexHttpBinding" contract="IMetadataExchange"/>-->
      </service>
    </services>
    <behaviors>
      <serviceBehaviors>
        <behavior name="metaExchange">
          <serviceMetadata httpGetEnabled="true"/>
          <!--<serviceMetadata/>-->
        </behavior>
      </serviceBehaviors>
    </behaviors>
  </system.serviceModel>
</configuration>

2.元数据交换终结点

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <system.serviceModel>
    <services>
      <service name="HelloWCFService.HelloWCFService" behaviorConfiguration="metaExchange">
        <host>
          <baseAddresses>
            <add baseAddress="http://localhost:8000/MyService"/>
          </baseAddresses>
        </host>
        <endpoint address="HelloWCFService" binding="wsHttpBinding" contract="HelloWCFService.IHelloWCFService"/>
        <endpoint address="metaExchange" binding="mexHttpBinding" contract="IMetadataExchange"/>
      </service>
    </services>
    <behaviors>
      <serviceBehaviors>
        <behavior name="metaExchange">
          <!--<serviceMetadata httpGetEnabled="true"/>-->
          <serviceMetadata/>
        </behavior>
      </serviceBehaviors>
    </behaviors>
  </system.serviceModel>
</configuration>

  

posted @ 2017-12-23 11:38  Hello_2018  阅读(748)  评论(0编辑  收藏  举报