超时:基础连接已关闭:连接意外关闭

时间:2013-04-18 18:01:47

标签: vb.net

我有超时问题。我正在连接的服务在及时响应时工作正常。当它花费大约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

1 个答案:

答案 0 :(得分:0)

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