【问题标题】:WebException: Unable to connect to the remote serverWebException:无法连接到远程服务器
【发布时间】:2011-04-29 09:41:24
【问题描述】:

我有一个客户端应用程序,它使用 WebHttpRequest 从外部服务器获取响应,它工作正常,但有时我得到以下异常......

System.Net.WebException:无法 连接远程服务器---> System.Net.Sockets.SocketException:一个 连接尝试失败,因为 关联方没有正确 一段时间后回复,或 建立连接失败,因为 连接的主机未能响应 xx.xx.xxx.xxx:xxx 在 System.Net.Sockets.Socket.DoConnect(端点 端点快照,套接字地址 套接字地址)在 System.Net.Sockets.Socket.InternalConnect(端点 远程EP)在 System.Net.ServicePoint.ConnectSocketInternal(布尔值 连接失败,套接字 s4,套接字 s6, Socket&socket,IPAddress&地址, ConnectSocketState 状态,IAsyncResult asyncResult,Int32 超时,异常& 例外)---内部结束 异常堆栈跟踪---

在 System.Net.HttpWebRequest.GetRequestStream(TransportContext& 上下文)

在 System.Net.HttpWebRequest.GetRequestStream()

....有什么帮助吗?

【问题讨论】:

    标签: c# web-services sockets exception


    【解决方案1】:

    这更像是“请求超时”错误。您尝试连接的服务器没有响应您的请求。您应该使用 try-catch 处理此异常,并在 catch 块中再次尝试连接 n 次。

    【讨论】:

    • 我也尝试增加超时时间,但没有解决。它适用于许多请求,但在许多成功事务的中间,会引发此异常并且没有时间或事务失败模式的数量。
    • 现在我得到一个特定的错误 System.Net.WebException:底层连接已关闭:发送时发生意外错误。 ---> System.IO.IOException: 身份验证失败,因为远程方已关闭传输流。在 System.Net.Security.SslState.StartReadFrame(Byte[] buffer, Int32 readBytes, AsyncProtocolRequest asyncRequest) 在 System.Net.Security.SslState.StartReceiveBlob(Byte[] buffer, AsyncProtocolRequest asyncRequest)。 --- 内部异常堆栈跟踪结束 ---
    • 似乎是服务器的问题,而不是您的代码。服务器可能需要在连接期间设置某些选项。
    • 感谢埃文。是的,它看起来在他们这边(网络服务器)而不是在客户端代码中。
    猜你喜欢
    • 2013-01-20
    • 2011-12-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-04-20
    • 2010-11-13
    相关资源
    最近更新 更多