0

I am doing a chat in C# and I got this error:

System.ServiceModel.EndpointNotFoundException: Could not connect to http://localhost:9000/MyService. TCP error code 10061: No connection could be made because the target machine actively refused it 127.0.0.1:9000

Here is the config file of the server :

<?xml version="1.0" encoding="utf-8" ?><configuration>
 <startup> 
    <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
</startup>

<system.serviceModel>
    <services>
        <service name="ChattingServer.ChattingService">
            <endpoint address="net.tcp://localhost:9000/MyService"
                binding="netTcpBinding" bindingConfiguration="" name="ChattingServiceEndPoint"
                contract="ChattingInterfaces.IChattingService" />
        </service>
    </services>
</system.serviceModel>

And here is for the client side:

<?xml version="1.0" encoding="utf-8" ?><configuration>
<startup> 
    <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
</startup>
<system.serviceModel>
    <client>
        <endpoint address="net.tcp://localhost:9000/MyService"
            binding="netTcpBinding" bindingConfiguration="" contract="ChattingInterfaces.IChattingService"
            name="ChattingServiceEndPoint" kind="" endpointConfiguration="" />
    </client>
</system.serviceModel>

I tried to fix it by activating the net.tcpListenerAdapter(Start->Service) but nothing happened. Thank you.

Heretic Monkey
  • 11,687
  • 7
  • 53
  • 122
  • The client cannot use Localhost (127.0.0.1) because the server is using same connection. The client should use the IP Address of computer of the Computer name instead of localhost:9000. A connection consists of 3 items 1) Source IP address 2) Destination IP address 3) Port number. You cannot have all 3 items the same. So the Server uses loopback 127.0.0.1 and client uses the IP address of computer. Your application has two connections, one for server and one for client. The connections must be different. – jdweng Aug 04 '16 at 16:26
  • When I have finished my app and I start it, it works but after some trials this issue comes. –  Aug 04 '16 at 16:27
  • My guess is someother application is using the same port your application is trying to use. – Рахул Маквана Aug 04 '16 at 16:28
  • Possible duplicate of [No connection could be made because the target machine actively refused it?](http://stackoverflow.com/questions/2972600/no-connection-could-be-made-because-the-target-machine-actively-refused-it) – Heretic Monkey Aug 04 '16 at 16:53
  • I can't tell if the connection ever completed or a restart occurred. The timeout could be long that the error message may not occur immediately. Use Netstat (run repetitively) to see if the connection ever completes. It is possible that the client may retry when a connection terminates. Best thing is to use a sniffer like fiddler to monitor the messages while application is running to find root cause. – jdweng Aug 04 '16 at 17:09

0 Answers0