Search code examples
wcfnettcpbinding

WCF net.tcp connection always fails


I tried to setup a service for testing using a net.tcp binding. I also set a http endpoint. The configuration is as follows:

  <system.serviceModel>
    <behaviors>
      <endpointBehaviors>
        <behavior name="Inbound_REST">
          <webHttp />
        </behavior>
      </endpointBehaviors>
      <serviceBehaviors>
        <behavior name="InboundHttpConfiguration">
          <serviceMetadata httpGetEnabled="true" />
          <serviceDebug includeExceptionDetailInFaults="true" />
        </behavior>
        <behavior name="InboundTcpConfiguration">
          <serviceMetadata httpGetEnabled="false" />
          <serviceDebug includeExceptionDetailInFaults="true" />
        </behavior>
      </serviceBehaviors>
    </behaviors>
    <services>
        <service behaviorConfiguration="InboundTcpConfiguration" name="Inbound">
          <endpoint address="" binding="netTcpBinding" contract="IContract">
            <identity>
              <dns value="localhost"/>
            </identity>
          </endpoint>
          <host>
            <baseAddresses>
              <add baseAddress="net.tcp://localhost:6969/Inbound" />
            </baseAddresses>
          </host>
        </service>
    </services>
    <serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
    <client>
      <endpoint name="httpEndPoint" address="http://localhost:1568/Inbound.svc" binding="basicHttpBinding" contract="IContract" />
       <endpoint name="tcpEndPoint" address="net.tcp://localhost:6969/Inbound" binding="netTcpBinding" contract="IContract" />
    </client>
    <bindings>
      <basicHttpBinding>
        <binding name="httpbind">
          <security mode="Transport">
            <transport clientCredentialType="None"/>
          </security>
        </binding>
      </basicHttpBinding>
      <netTcpBinding>
        <binding name="tcpbind">
          <security mode="Transport">
            <transport clientCredentialType="None" />
          </security>
        </binding>
      </netTcpBinding>
    </bindings>
  </system.serviceModel>

When I attempt to consume the service using the net.tcp binding, it always return me the error:

Could not connect to net.tcp://localhost:6969/Inbound. The connection attempt lasted for a time span of 00:00:00.9531494. TCP error code 10061: No connection could be made because the target machine actively refused it 127.0.0.1:6969.

By the way, the http binding works fine. I think it could be some machine configuration, but wasn't able to find what's the root cause.


Solution

  • If you are trying to run your WCF service through visual studio netTcpBinding is not supported. Sorry!

    Check out this post for a more detailed explanation.