【问题标题】:0x80004005 A connection attempt failed because the connected party did not properly respond after a period of time0x80004005 连接尝试失败,因为连接方在一段时间后没有正确响应
【发布时间】:2014-01-07 13:54:29
【问题描述】:

我在从 ASP.NET 应用程序访问 Web 服务时遇到了这个问题。
但是当它托管在 Windows 服务器中时会出现问题。
当它托管在桌面上时,它工作正常。
我正在使用 HttpWebRequest 对象调用 Web 服务。

即使它在 HTML/Java Script 应用程序的服务器中也能正常工作。仅在服务器中托管的 ASP.NET 应用程序中出现问题。我收到以下错误。 IIS 8.0 已安装在服务器中。

Unable to connect to the remote server
System.Net.Sockets.SocketException (0x80004005): A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond 153.2.228.76:443 at System.Net.Sockets.Socket.DoConnect(EndPoint endPointSnapshot, SocketAddress socketAddress) at System.Net.ServicePoint.ConnectSocketInternal(Boolean connectFailure, Socket s4, Socket s6, Socket& socket, IPAddress& address, ConnectSocketState state, IAsyncResult asyncResult, Exception& exception)
at System.Net.HttpWebRequest.GetRequestStream(TransportContext& context) at System.Net.HttpWebRequest.GetRequestStream() at VSPTestApplication.UPS.CalculateRate_Click(Object sender, EventArgs e)
System.IO.Stream GetRequestStream(System.Net.TransportContext ByRef) 

【问题讨论】:

  • 欢迎来到 SO。通过托管在您的桌面上,您的意思是作为服务客户端的 ASP.NET 应用程序和服务运行在同一台机器上,即您的开发机器上?稍微细化您的问题,以更清楚地了解您正在排除故障的情况与有效的情况。
  • 非常感谢您的回复。它只是一个 ASP.NET 应用程序。我的意思是当它托管在安装在我桌面上的 IIS 中时,它工作正常。但是我在安装在 Windows 服务器中的 IIS 中托管相同的应用程序,然后它无法正常工作。
  • 如果当您收到错误时,作为服务客户端的 ASP.NET 应用程序和服务位于不同的机器上,那么您需要对从客户端机器到托管服务的远程机器的连接进行故障排除。简单 - 例如网络浏览器,telnet 等。
  • 它不是服务客户端,它只是一个 ASP.NET 应用程序。从带有 HTML/Java 脚本应用程序的 Web 浏览器测试连接性很好。当 ASP.NET 应用程序托管在 Windows 服务器的 IIS 中时,它无法在 ASP.NET 应用程序中运行。

标签: asp.net web-services httpwebrequest httpwebresponse


【解决方案1】:

从您的错误消息来看,我注意到您正在尝试访问 HTTPS 网址。在 IIS 中的 aspnet 中运行时,这可能会很棘手,因为您的代码在不同的用户上下文中运行。并且可能不会在该上下文中安装必要的证书。例如,如果目标服务器有一个由客户端机器不信任的 CA 签名的证书 (asp.net/iis/windows),那么请求将不会成功。

但是,证书错误会很明显。它不会显示为连接失败。

我建议使用 system.net 日志工具来创建日志文件。这应该有助于解决问题。此外,您应该在 Windows 服务器上运行 wireshark 并查看服务器尝试连接的位置。可能很简单,因为 Windows 服务器没有与目标的连接。或者中间可能有一个代理搞砸了网络路径。

要设置 system.net 日志记录,您可以将以下配置文件放在与运行您的代码的应用相同的目录中。

<?xml version="1.0" encoding="UTF-8" ?>

<configuration>
<system.diagnostics>
<trace autoflush="true" />

<sources>
<source name="System.Net">

<listeners>
    <add name="System.Net"/>
</listeners>
</source>
<source name="System.Net.Sockets">
<listeners>
    <add name="System.Net"/>
</listeners>
</source>
<source name="System.Net.Cache">
<listeners>
    <add name="System.Net"/>
</listeners>
</source>
</sources>
<sharedListeners>
    <add
        name="System.Net"
        type="System.Diagnostics.TextWriterTraceListener"
        initializeData="System.Net.trace.log"
    />
</sharedListeners>
<switches>
    <add name="System.Net" value="Verbose" />
    <add name="System.Net.Sockets" value="Verbose" />               
    <add name="System.Net.Cache" value="Verbose" />
</switches>

有关日志记录的更多详细信息:

creating a tracelog with system.net

【讨论】:

    【解决方案2】:

    我也遇到了同样的问题,只是通过排除网络故障就解决了。

    在 windows-> 设置 -> 网络和 Internet -> 网络疑难解答

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2013-06-13
      • 2016-08-30
      • 2020-06-19
      • 1970-01-01
      • 2011-10-29
      • 2021-10-06
      相关资源
      最近更新 更多