0
我有一個WCF服務每分鐘運行頻繁(1000+)出站連接到外部API。HttpWebRequest - GetResponse() - WebException ReceiveFailure
我的代碼拋出以下異常頻繁,但並非總是如此表示作爲與引發WebException狀態屬性是ReceiveFailure
即拍即出站請求的代碼引發WebException如下:
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(paramBuilder.ToString());
request.ServicePoint.ConnectionLeaseTimeout = 0;
request.Method = "GET";
request.Timeout = 33000; //33 Second Timeout Is By Design
Stream stream = default(Stream);
HttpWebResponse response = default(HttpWebResponse);
try
{
response = (HttpWebResponse) request.GetResponse();
stream = response.GetResponseStream();
reader = new StreamReader(stream,Encoding.UTF8);
string str = reader.ReadToEnd();
return str;
}
catch (WebException exception)
{
//Handle WebException
}
catch (Exception exception)
{
//Handle Exception
}
finally
{
if (reader != null)
reader.Dispose();
if (response != null)
response.Close();
if (stream != null)
stream.Dispose();
}
異常堆棧跟蹤顯示異常是由GetResponse()引起的。
什麼可能導致這種情況發生,我偶爾會收到WebException -ReceiveFailure。
我已經參考了這個狀態的MSDN文檔,但是這並沒有幫助我。