How to publish service metadata for your clients

J.D. Meier, Jason Taylor, Prashant Bansode, Carlos Farre, Madhu Sundararajan, Steve Gregersen.

To publish service metadata for your clients:
  1. If your service uses HTTP binding you will need to enable metadata via http get or https get. HTTP get will be required if you are not using transport security. HTTPS get will be required if you are using transport security. The trade off with this configuration is that clients will be able to browse your service metadata with browser.
<serviceMetadata httpsGetEnabled="true" />
<serviceMetadata httpGetEnabled="true"  />
  1. If your service uses HTTP binding you can use a mex endpoint without enabling http get or https get. In this case Browsers will not be able to browse metadata while will be able to create proxies using the mex endpoint. The tradeoff with this configuration is that mexendpoints are not possible if IIS does not have anonymous authentication enabled
<system.serviceModel>
     <bindings>
      <wsHttpBinding>
        <binding name="BindingConfiguration">
          <security>
            <message clientCredentialType="Certificate" />
          </security>
        </binding>
      </wsHttpBinding>
    </bindings>
    <services>
      <service behaviorConfiguration="BehaviorConfiguration" name="Service">
        <endpoint address="" binding="wsHttpBinding" bindingConfiguration="BindingConfiguration"
          name="WsBinding" contract="IService" />
*        <endpoint address="mex" binding="mexHttpBinding" bindingConfiguration=""*
*          name="mexendpoint" contract="IMetadataExchange" />*
      </service>
    </services>
    <behaviors>
      <serviceBehaviors>
        <behavior name="BehaviorConfiguration">
          <serviceDebug includeExceptionDetailInFaults="true" />
          <serviceCredentials>
            <serviceCertificate findValue="CN=tempCert" />
          </serviceCredentials>
*          <serviceMetadata />*
        </behavior>
      </serviceBehaviors>
    </behaviors>
  </system.serviceModel>
  1. If your service uses HTTP binding you can use a custom endpoint that implements IMetadataExchange without enabling http get or https get. In this case Browsers will not be able to browse metadata while will be able to create proxies using the mex endpoint. Additionally you will be able to use the mex endpoint with any authentication scheme
<bindings>
    <wsHttpBinding>
      <binding name="wsHttpEndpointBinding">
        <security mode="Transport">
          <transport clientCredentialType="Certificate" />
        </security>
      </binding>
    </wsHttpBinding>
  </bindings>
  ...
  <services>
    <service behaviorConfiguration="returnFaults" name="MyService">
      <endpoint binding="wsHttpBinding" bindingConfiguration="wsHttpEndpointBinding"
        name="wsHttpEndpoint" contract="IService" />
      <endpoint address="mex" binding="wsHttpBinding" 
        bindingConfiguration="wsHttpEndpointBinding"
        name="mexEndpoint" contract="IMetadataExchange" />
    </service>
  </services>…
  1. If your service does not use HTTP binding, you will need to configure a service metadata and create a mex endpoint
<system.serviceModel>
    <behaviors>
      <serviceBehaviors>
        <behavior name="BehaviorConfiguration">
          <serviceDebug includeExceptionDetailInFaults="true" />
          *<serviceMetadata />*
        </behavior>
      </serviceBehaviors>
    </behaviors>
    <bindings>
      <netTcpBinding>
        <binding name="BindingConfiguration">
          <security mode="Message">
            <message clientCredentialType="Windows" />
          </security>
        </binding>
      </netTcpBinding>
    </bindings>
    <services>
      <service behaviorConfiguration="BehaviorConfiguration" name="WCFServicecHost.MyService">
        *<endpoint address="Mex" binding="mexTcpBinding" bindingConfiguration=""*
*          name="MexEndpoint" contract="IMetadataExchange" />*
        <endpoint address="" binding="netTcpBinding" bindingConfiguration="BindingConfiguration"
          name="TcpBinding" contract="WCFServicecHost.IMyService" />
        <host>
          <baseAddresses>
            <add baseAddress="net.tcp://perfpres02.npscode.com/MyService" />
          </baseAddresses>
        </host>
      </service>
    </services>
  </system.serviceModel>

Last edited May 8, 2008 at 6:45 AM by prashantbansode, version 1

Comments

No comments yet.