简体   繁体   中英

Getting connection refused when calling a web service from a web app works fine from localhost

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM