Search code examples
wcfiisweb-confignettcpbinding

Multiple WCF service endpoints in IIS breaks wcftestclient


I'm trying to expose a WCF service through both http and net.tcp binding in IIS. Everything seems to work as expected when I specify just the net.tcp bindings, or just the http bindings, but when I add both the wcftestclient program and all other service proxy generators fail:

Error: Cannot obtain Metadata from net.tcp://host/application/service.svc ... Metadata Exchange Error URI: net.tcp://host/application/service.svc Metadata contains a reference that cannot be resolved: 'net.tcp://host/application/service.svc '. There was > no endpoint listening at net.tcp://host/application/service.svc that could accept the message. This is often caused by an incorrect address or SOAP action. See InnerException, if present, for more details.

My web.config looks like this:

<?xml version="1.0"?>
<configuration>
  <system.serviceModel>
    <services>      
      <service behaviorConfiguration="ServiceBehavior" name="MyServiceBehavior">
        <endpoint address="mex-http"      binding="mexHttpBinding"   name="mex-http" contract="IMetadataExchange" />
        <endpoint address="service-http"  binding="basicHttpBinding" name="db-http"  contract="IMyService" />
        <endpoint address="mex-tcp"       binding="mexTcpBinding"    name="mex-http" contract="IMetadataExchange" />
        <endpoint address="service-tcp"   binding="netTcpBinding"    name="db-http"  contract="IMyService" />
      </service>      
    </services>
    <behaviors>
      <serviceBehaviors>
        <behavior name="MyServiceBehavior">
          <serviceMetadata httpGetEnabled="true" httpsGetEnabled="false"/>
        </behavior>
      </serviceBehaviors>
    </behaviors>
  </system.serviceModel>
</configuration>

So, if I remove the mex-http and db-http endpoints, everything is fine. If I don't, the service is accessible over http but not over tcp. If I remove the tcp endpoints, of course the http one is still available. Any thoughts?

Edit: Based on Marc's suggestion, I changed the relevant net.tcp endpoints to read

<endpoint name="mex-http" address="net.tcp://localhost/myservice/MyService.svc/mex" binding="mexTcpBinding" contract="IMetadataExchange" />
<endpoint name="db-http"  address="net.tcp://localhost/myservice/MyService.svc"     binding="netTcpBinding" contract="IMyService" />

which works as expected!


Solution

  • Have you checked out

    Have you completed those steps to make net.tcp available in IIS / WAS?

    Assuming you have - I believe hosting a net.tcp WCF service in WAS requires you to either define a net.tcp base address and/or complete addresses on the net.tcp endpoints - since those things are not defined by the IIS virtual directory.

    So try:

    <services>      
       <service behaviorConfiguration="ServiceBehavior" name="MyServiceBehavior">
           ...(your http stuff here)....
           <endpoint name="mex-http" 
               address="net.tcp://YourServer:7171/NetTcpService/mex"       
               binding="mexTcpBinding"    
               contract="IMetadataExchange" />
           <endpoint name="db-http"  
               address="net.tcp://YourServer:7171/NetTcpService/MyService"       
               binding="netTcpBinding"    
               contract="IMyService" />
      </service>      
    </services>
    

    or:

    <services>      
       <service behaviorConfiguration="ServiceBehavior" name="MyServiceBehavior">
          <host>
             <baseAddresses>
                <add baseAddress="net.tcp://YourServer:7171/NetTcpService"/>
             </baseAddresses>
           </host>
           ...(your http stuff here)....
           <endpoint name="mex-http" 
               address="mex"
               binding="mexTcpBinding"    
               contract="IMetadataExchange" />
           <endpoint name="db-http"  
               address="MyService"
               binding="netTcpBinding"    
               contract="IMyService" />
      </service>      
    </services>