我遇到超時問題。我正在連接的服務在及時響應時工作正常。當大約需要10秒時,它會超出例外。除了超時和ReadWriteTimeout之外,還可以設置其他超時屬性以便它能夠正常等待?有什麼我需要在TCP/IP級別設置?謝謝你的幫助。超時:底層連接已關閉:連接意外關閉
System.Net.WebException:底層連接已關閉:連接意外關閉。 at 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
您是否檢查過IIS中的超時設置?或者你正在使用的任何Web服務器(你沒有指定)。 – Melanie
媚蘭。感謝您及時的回覆。它實際上是一個本地Web服務,超時。我們有第三方服務,我們執行帖子並獲取。例如:HTTP://10.10.50.28:22280/transaction/identifyCustomer –
恐怕我對超時設置的想法是我所得到的。希望別人能夠幫助你。祝你好運! – Melanie