user1403505
user1403505

Reputation: 1005

WCF net.tcp communication error

I created a WCF Service with net.tcp binding and I was able to add a service reference to it in my console application without errors.

After doing this I am trying to self host this service in my console app. The service Host gets opened but when I call a method in the service with the service reference object I get this exception

'Could not connect to net.tcp://localhost/Design_Time_Addresses/MyWCFServiceLibrary/Service2/. The connection attempt lasted for a time span of 00:00:02.0800000. TCP error code 10061: No connection could be made because the target machine actively refused it [::1]:808.'

This is my cs file code

Main method()

 Service2Client sc2 = new Service2Client();
                Uri baseaddress = new Uri("net.tcp://localhost:8732/Design_Time_Addresses/MyWCFServiceLibrary/Service2/");

                ServiceHost serviceHost = new ServiceHost(typeof(Service2Client), baseaddress);

                serviceHost.Open();

                Console.WriteLine(sc2.GetData(124)); --> exception comes at this point

                Console.ReadLine();

This is app.config in console app

<system.serviceModel>
    <client>
      <endpoint address="net.tcp://localhost/Design_Time_Addresses/MyWCFServiceLibrary/Service2/"
        binding="netTcpBinding" bindingConfiguration="NetTcpBinding_IService2"
        contract="ServiceReference2.IService2" name="NetTcpBinding_IService2">
        <identity>
          <dns value="localhost" />
        </identity>
      </endpoint>
    </client>
    <bindings>
      <netTcpBinding>
        <binding name="NetTcpBinding_IService2" closeTimeout="00:01:00"
          openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00"
          transactionFlow="false" transferMode="Buffered" transactionProtocol="OleTransactions"
          hostNameComparisonMode="StrongWildcard" listenBacklog="10" maxBufferPoolSize="524288"
          maxBufferSize="65536" maxConnections="10" maxReceivedMessageSize="65536">
          <readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"
            maxBytesPerRead="4096" maxNameTableCharCount="16384" />
          <reliableSession ordered="true" inactivityTimeout="00:10:00"
            enabled="false" />
          <security mode="None">
            <transport clientCredentialType="Windows" protectionLevel="EncryptAndSign" />
            <message clientCredentialType="Windows" />
          </security>
        </binding>
      </netTcpBinding>
    </bindings>
    <!--<client>
      <endpoint address="net.tcp://localhost:8732/Design_Time_Addresses/MyWCFServiceLibrary/Service2/"
        binding="netTcpBinding" bindingConfiguration="NewBinding0" contract="MyWCFServiceLibrary.IService2"
        name="endpointClient" />
      <endpoint address="net.tcp://localhost/Design_Time_Addresses/MyWCFServiceLibrary/Service2/"
        binding="netTcpBinding" bindingConfiguration="NetTcpBinding_IService2"
        contract="ServiceReference2.IService2" name="NetTcpBinding_IService2">
        <identity>
          <dns value="localhost" />
        </identity>
      </endpoint>
    </client>-->
  </system.serviceModel>

Environment: Vs2010

Can any one please help me on this.

Upvotes: 0

Views: 3116

Answers (3)

Umer Waheed
Umer Waheed

Reputation: 4594

There can be multiple reasons as other answers can resolve the problem. But In my case, the problem solved after installing pending windows update.

Upvotes: 0

Rajesh
Rajesh

Reputation: 7886

Your client config has the URL as

net.tcp://localhost/Design_Time_Addresses/MyWCFServiceLibrary/Service2/

whereas your service is on

net.tcp://localhost:8732/Design_Time_Addresses/MyWCFServiceLibrary/Service2/

The PORT Number is missing in the app.config of your console app client endpoint element.

Upvotes: 2

serge.karalenka
serge.karalenka

Reputation: 990

It's possible that:

1) the firewall is blocking the request. Check it out.

2) make sure that

  • Net.Tcp Listener Adapter;
  • Net.Tcp Port Sharing Service

are running (Windows Services)

Upvotes: 2

Related Questions