0

NET Web application which calls a remote web service to get some information. When I deploy the web application to my local machine's IIS and run it is is able to access the remote web service fine. However if I deploy the web application to one of the live servers, I get System.Net.Sockets.SocketException:

No connection could be made because the target machine actively refused it 87.224.86.167:8080

The C# code I am using to make the request is pretty simple:

using (var client = new System.Net.WebClient())
{
    string data = "{\"operation\":\"logon\", \"username\":\"" + hwCommUsername + "\", \"password\":\"" + hwCommPassword + "\"}";
    byte[] response = client.UploadData(uri, "PUT", Encoding.UTF8.GetBytes(data));
    string jsonResponse = Encoding.UTF8.GetString(response);
    object decoded = EncoderHelper.JsonDecode(jsonResponse);
}

Any idea why?

Update: Example Uri I am accessing is : http://a23416.loco-pos.net which is a valid URI with the corrent credentials being passed in.

user1984695
  • 77
  • 1
  • 2
  • 10

1 Answers1

2

Reference this StackoverFlow Posting No connection could be made because the target machine actively refused it

"Actively refused it" means that the host sent a reset instead of an ack when you tried to connect. It is therefore not a problem in your code. Either there is a firewall blocking the connection or the process that is hosting the service is not listening on that port, this may be because it is not running at all or because it is listening on a different port.

once you start the process hosting your service try netstat -anb (requires admin privileges) to verify that it is running and listening on the expected port.

Community
  • 1
  • 1
  • reference http://stackoverflow.com/questions/2972600/no-connection-could-be-made-because-the-target-machine-actively-refused-it – Nelson Patricio Jimenez Jan 16 '13 at 18:21
  • +2Nelson I added your link as part of your answer – MethodMan Jan 16 '13 at 18:24
  • @Neslson: What you are saying makes sense. What I don't get is why would the same web service listening at the same address and port fulfill requests from localhost and at the same time refuse/reset it from the live server and do this consistently? I cannot run netstat on the server running the web service because it is a thrid party. – user1984695 Jan 17 '13 at 07:29
  • I have found the problem. It was the firewall on the web server.thanks – user1984695 Jan 18 '13 at 08:26