2013-04-18 202 views
2

我遇到超時問題。我正在連接的服務在及時響應時工作正常。當大約需要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 
+0

您是否檢查過IIS中的超時設置?或者你正在使用的任何Web服務器(你沒有指定)。 – Melanie

+0

媚蘭。感謝您及時的回覆。它實際上是一個本地Web服務,超時。我們有第三方服務,我們執行帖子並獲取。例如:HTTP://10.10.50.28:22280/transaction/identifyCustomer –

+0

恐怕我對超時設置的想法是我所得到的。希望別人能夠幫助你。祝你好運! – Melanie

回答

0

Timeout值要設置爲60000,轉化爲大約1分鐘,因爲Timeout值單位爲毫秒。 1000的值是1秒。 因此,請嘗試將其設置爲更高的值。例如嘗試將其設置爲5或10分鐘進行測試。

+0

這並沒有幫助。這就像是超時無法識別。連接僅在10秒後關閉。 –

+0

如果將'_httpRequest.KeepAlive = True'設置爲' –

+0

會發生同樣的錯誤。 –

相關問題