2

我遇到了超时问题。我连接的服务在及时响应时运行良好。当它需要大约 10 秒时,它会超时,但有异常。除了 Timeout 和 ReadWriteTimeout,我还可以设置哪些其他超时属性以使其正常等待?我需要在 TCP/IP 级别设置什么吗?谢谢你的帮助。

System.Net.WebException:基础连接已关闭:连接意外关闭。在 System.Net.HttpWebRequest.GetResponse()

这是我的代码。我尝试了很多东西的变体:

'The post works
Dim _httpRequest As HttpWebRequest
_httpRequest = WebRequest.Create("mywebservice")
System.Net.ServicePointManager.Expect100Continue = False
_httpRequest.Credentials = CredentialCache.DefaultCredentials
_httpRequest.ProtocolVersion = HttpVersion.Version10
'This is a 60 second wait
_httpRequest.Timeout = 60000 
'This is a 60 second wait
_httpRequest.ReadWriteTimeout = 60000
_httpRequest.KeepAlive = False
_httpRequest.Method = "POST"

'If the response takes takes 10 seconds
'This is the message we get:  System.Net.WebException: The underlying connection was closed: The connection was closed unexpectedly.

_httpRequest.Method = "GET"
_httpRequest.ContentType = "text/xml"
'The error is here
Dim httpResponse As HttpWebResponse = _httpRequest.GetResponse
4

1 回答 1

0

您设置的Timeout值是 60000,转换为大约 1 分钟,因为Timeout值以毫秒为单位。值 1000 是 1 秒。因此,请尝试将其适当地设置为更高的值。例如,尝试将其设置为 5 或 10 分钟进行测试。

于 2013-04-18T20:25:38.730 回答