4

I have been developing a web service and a windows service, the web service I have deployed is in another server, and the windows service I have deployed works in my own server, so I use the windows service to call the web service. Everything was fine, but in a few days I have received the below message:

System.Net.WebException: Unable to connect to the remote server ---> 
System.Net.Sockets.SocketException: No connection could be made 
because the target machine actively refused it 127.0.0.1:57240
at 
System.Net.Sockets.Socket.DoConnect(EndPoint endPointSnapshot, SocketAddress 
socketAddress) at System.Net.Sockets.Socket.InternalConnect(EndPoint remoteEP)
at
System.Net.ServicePoint.ConnectSocketInternal(Boolean connectFailure, Socket s4,Socket 
s6, Socket& socket, IPAddress& address, ConnectSocketState state, IAsyncResult asyncResult, Int32 timeout, Exception& exception)
--- End of inner exception stack trace -
-- at System.Net.HttpWebRequest.GetRequestStream(TransportContext& context)
at System.Net.HttpWebRequest.GetRequestStream()
at System.Web.Services.Protocols.SoapHttpClientProtocol.Invoke(String methodName, Object[] parameters)
Mehraban
  • 3,164
  • 4
  • 37
  • 60
Mohammad Bahsoun
  • 39
  • 1
  • 1
  • 4
  • You say you deployed the web servec and the windows service on different computers. Note that your windows service tries to connect to 127.0.0.1, which is the loop-back device. That means the Windows service tries to connect to the same machine it is running on and not the machine of the web service. Make sure the Windows service is using the IP address of the machine running the web service... –  Jun 07 '14 at 11:31
  • may you should check if firewall is not the one which is causing the problem. – Sachin Trivedi Jun 07 '14 at 11:31
  • @mohd, See http://stackoverflow.com/questions/2972600/no-connection-could-be-made-because-the-target-machine-actively-refused-it – Pacerier Apr 03 '15 at 18:19

3 Answers3

3

because the target machine actively refused it 127.0.0.1:57240

The "target machine" in this case is the machine on which the failing code is running. Not the remote machine. 127.0.0.1 is the IP address of "localhost", you use it to get two processes that run on the same machine to talk to each other through sockets. Not unusual, it can be an easier alternative to using named pipes for example.

But of course you expect it to connect to another machine, one that actually has an application listening. Something is wrong with your program's config, it is trying to connect to a service that doesn't exist. There's no insight in how that could have happened, your question is missing all details about exactly how you selected the target machine. If you selected it by name rather than IP address then there's something very screwy going on with the naming service on your LAN. Or you simply forgot to change the config when you went from testing mode to deployment mode. Or you gave up trying a bunch of stuff that didn't work because the firewall is blocking access.

Hans Passant
  • 922,412
  • 146
  • 1,693
  • 2,536
  • thank you sir for your reply. Regarding to the point"how you selected the target machine" i select the target machine by using real ip. Note: after deploy the web service everything is fine but in few day ago i have received the error message the target machine refused... – Mohammad Bahsoun Jun 08 '14 at 11:51
0

I think, you need to check your proxy settings in "internet options". If you are using proxy/'hide ip' applications, this problem may be occurs.

In my case i changed proxy settings.

isaeid
  • 543
  • 5
  • 26
0

Port 57240 looks like a client's application port, your server application is probably running on lower port. So it looks like client crashed and the communication socket was closed.

Cary Bondoc
  • 2,923
  • 4
  • 37
  • 60
user61253764
  • 478
  • 5
  • 9