Dinesh
Dinesh

Reputation: 3780

How is the Binding done when specifying multiple Base Address

I have a WCF Service which has it's configuration file as specified below:

<system.serviceModel>
  <services>
    <service name="WCFService.ServiceClass" behaviorConfiguration="metaDataSupport">
      <host>
        <baseAddresses>
          <add baseAddress="net.pipe://localhost/WCFService"/>
          <add baseAddress="net.tcp://localhost:8100/WCFService"/>
          <add baseAddress="http://localhost:8101/WCFService"/>
        </baseAddresses>
      </host>
      <endpoint address="tcpmex"
                binding="mexTcpBinding"
                contract="IMetadataExchange" />
      <endpoint address="namedpipemex"
                binding="mexNamedPipeBinding"
                contract="IMetadataExchange" />
      <endpoint address=""
                binding="wsHttpBinding"
                contract="WCFService.IServiceClass" />
    </service>
  </services>
  <behaviors>
    <serviceBehaviors>
      <behavior name="metaDataSupport">
        <serviceMetadata httpGetEnabled="false" httpGetUrl="" />
      </behavior>
    </serviceBehaviors>
  </behaviors>
</system.serviceModel>

I have 3 types of binding here: NamedPipeBinding, TcpBinding and wsHttpBinding.

I can add a reference with metadata at the following location

  1. net.tcp://localhost:8100/WCFService/tcpmex

  2. net.pipe://localhost/WCFService/namedpipemex

I have disabled the httpGet for the service in behavior.

The service reference is added but with the following configuration at client:

<system.serviceModel>
  <bindings>
    <wsDualHttpBinding>
      <binding name="WSHttpBinding_IServiceClass" />
    </wsDualHttpBinding>
  </bindings>
  <client>
    <endpoint address="http://localhost:8101/WCFService" binding="wsHttpBinding"
      bindingConfiguration="WSHttpBinding_IServiceClass" contract="TCP.IServiceClass"
      name="WSHttpBinding_IServiceClass">
    </endpoint>
  </client>
</system.serviceModel>

But since I added a reference using TCP Binding endpoint, I expected :

address=net.tcp://localhost:8100/WCFService

and binding="mexTcpBinding"

The Service is working but I would like to know, What's going on here. What is the reason for this. Is it due to the baseAddress or some preference is given to wsHttpBinding?

Thoughts are appreciated.

Thanks.

Upvotes: 2

Views: 316

Answers (1)

carlosfigueira
carlosfigueira

Reputation: 87308

The mex binding (short for Metadata EXchange) is not an endpoint which can be used to consume your service. Instead, it's used only used to expose information (or meta information) about all the "real" endpoints of your service - notice that your service class doesn't implement the IMetadataExchange contract which you defined in your TCP/Pipe endpoints.

In your case, your service has only one "real" endpoint - the one using wsHttpBinding, which implements the WCFService.IServiceClass interface. That's why there's only one endpoint in your client configuration.

Now, if you had another endpoint using a non-metadata binding (and not the IMetadataExchange contract), they would show up in the client config as well:

<system.serviceModel>
  <services>
    <service name="WCFService.ServiceClass" behaviorConfiguration="metaDataSupport">
      <host>
        <baseAddresses>
          <add baseAddress="net.pipe://localhost/WCFService"/>
          <add baseAddress="net.tcp://localhost:8100/WCFService"/>
          <add baseAddress="http://localhost:8101/WCFService"/>
        </baseAddresses>
      </host>
      <endpoint address="tcpmex"
                binding="mexTcpBinding"
                contract="IMetadataExchange" />
      <endpoint address="namedpipemex"
                binding="mexNamedPipeBinding"
                contract="IMetadataExchange" />
      <endpoint address=""
                binding="netNamedPipeBinding"
                contract="WCFService.IServiceClass" />
      <endpoint address=""
                binding="netTcpBinding"
                contract="WCFService.IServiceClass" />
      <endpoint address=""
                binding="wsHttpBinding"
                contract="WCFService.IServiceClass" />
    </service>
  </services>
  <behaviors>
    <serviceBehaviors>
      <behavior name="metaDataSupport">
        <serviceMetadata httpGetEnabled="false" httpGetUrl="" />
      </behavior>
    </serviceBehaviors>
  </behaviors>
</system.serviceModel>

Upvotes: 1

Related Questions