1. 程式人生 > >C# WCF發布服務的元數據的方式

C# WCF發布服務的元數據的方式

httpbind pan local metadata XML pos avi 終結點 host

發布服務元數據的方式有兩種:一是基於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>

  

C# WCF發布服務的元數據的方式