让我描述一下情况。我有一个Windows(让我们将其命名为A__),其中calls是一个Web(让我们给他命名为B__)。B自己调用不同的网络服务。(让我们称之为Web WS1, WS3__)
绘图:
//This is a Black Box (e.g. I can't change implementation)
+-----------------------------------------------+
| |
| ----> WS1 |
WindowsService A ----> | Webservice B ----> WS2 |
| ----> WS3 |
| |
+-----------------------------------------------+在调用过程中,可能会不时发生异常。大多数例外情况应该停止程序的执行并通知开发人员(Me)。但是当发生Timeout时,Window-Service 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,而不使用这里提到的消息(手柄TimeoutException),那么是否需要过滤。是否有任何字段可以指向基础异常的类型?
发布于 2014-10-15 07:37:51
尝试这段代码,它可能会帮助您认识到错误的原因:
PS:在catch()中使用它
string pageContent = new StreamReader(wex.Response.GetResponseStream()).ReadToEnd().ToString();
return pageContent;https://stackoverflow.com/questions/26376779
复制相似问题