Search code examples
c#wcfwindows-services

TCP error code 10061 : Could not connect to net.tcp://. The connection attempt lasted for a time span of 00:00:01.0156241


I have a windows service installed in the server(IP: 10.60.8.27, port 7002). When trying to connect from a WCF service hosted in another server(10.60.8.28) the following error occurs. This error occurs occasionally. When I restart the windows service, it works perfectly. How can I fix this issue? My servers are (Windows Server 2012 R2).

The error is :

Could not connect to net.tcp://10.60.8.27:7002/MyService. The connection attempt lasted for a time span of 00:00:01.0156241. TCP error code 10061: No connection could be made because the target machine actively refused it 10.60.8.27:7002. 

Solution

  • I have a little confused about your issue, not fully understanding your scenario.
    In my opinion, when the server secures the communication with a certificate, the client usually generates a DNS identity to verify the server identity when adding service reference. this might lead to the above error.

    <client>
        <endpoint address="net.tcp://vabqia969vm:21011/" binding="netTcpBinding"
            bindingConfiguration="NetTcpBinding_IService1" contract="ServiceReference1.IService1"
            name="NetTcpBinding_IService1">
            <identity>
                <dns value="vabqia969VM" />
            </identity>
        </endpoint>
    </client>
    

    DNS tag allows the client to verify the server identity when the server secures the communication with a certificate.
    https://learn.microsoft.com/en-us/dotnet/framework/wcf/feature-details/service-identity-and-authentication
    Besides, we also can’t rule out the performance of the machine. If there is a soaring amount of the client request to the server in an instant, basically there exists a multitude of requests timeout.
    Anyway, please try it and give me feedback.