SoapException中存在不同的TimeoutException
本文关键字:TimeoutException 存在 SoapException | 更新日期: 2023-09-27 18:26:30
让我描绘一下情况。我有一个Windows服务(让我们将其命名为A
),calls
是一个Web服务(让他命名为B
)B
自己在不同的Web服务上调用。(让我们将这些Web服务称为WS1
、WS2
、WS3
)
图纸:
//This is a Black Box (e.g. I can't change implementation)
+-----------------------------------------------+
| |
| ----> WS1 |
WindowsService A ----> | Webservice B ----> WS2 |
| ----> WS3 |
| |
+-----------------------------------------------+
在通话过程中可能会不时出现异常大多数异常应停止执行程序并通知开发人员(Me)。但是当出现Timeout
时,则窗口服务A
应当尝试retry
。
所以我写了以下代码:
try
{}
catch (WebException ex)
{
if (ex.Status == WebExceptionStatus.Timeout)
{
//Wait some time before retry
//Log the exception
//Retry
}
else
{
//Log the exception
throw;
}
}
catch (Exception ex)
{
//Log the exception
throw;
}
如果异常发生在Web服务B
中,则此代码非常有效。然而当timeout
出现在WS1
、WS2
、WS3
中时;我要拿SoapException
。
问题:
如果SoapException
的原因是Timeout
,而不使用这里提到的消息(MSDN-Handle TimeoutException),是否有任何方法可以过滤掉。是否有任何字段可以指向基础异常的类型?
试试这段代码,它可能会帮助您了解错误的原因:
PS:在catch()
中使用
string pageContent = new StreamReader(wex.Response.GetResponseStream()).ReadToEnd().ToString();
return pageContent;