简体   繁体   English

从Web应用程序调用Web服务时拒绝连接时,可以从本地主机正常工作

[英]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. NET Web应用程序,该应用程序调用远程Web服务以获取一些信息。 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. 将Web应用程序部署到本地计算机的IIS并运行时,它可以正常访问远程Web服务。 However if I deploy the web application to one of the live servers, I get System.Net.Sockets.SocketException: 但是,如果将Web应用程序部署到其中一台实时服务器,则会得到System.Net.Sockets.SocketException:

No connection could be made because the target machine actively refused it 87.224.86.167:8080 无法建立连接,因为目标计算机主动拒绝了该连接87.224.86.167:8080

The C# code I am using to make the request is pretty simple: 我用来发出请求的C#代码非常简单:

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. 更新:我正在访问的示例Uri是: http : //a23416.loco-pos.net ,这是一个有效的URI,传入了相应的凭证。

Reference this StackoverFlow Posting No connection could be made because the target machine actively refused it 引用此StackoverFlow发布无法建立连接,因为目标计算机主动拒绝了它

"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. 一旦开始托管服务的进程,请尝试netstat -anb (需要管理员权限)以验证其是否正在运行并且正在侦听预期的端口。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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