SoapException中存在不同的TimeoutException

本文关键字:TimeoutException 存在 SoapException | 更新日期: 2023-09-27 18:26:30

让我描绘一下情况。我有一个Windows服务(让我们将其命名为Acalls是一个Web服务(让他命名为BB自己在不同的Web服务上调用。(让我们将这些Web服务称为WS1WS2WS3

图纸:

                       //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出现在WS1WS2WS3中时;我要拿SoapException

问题:
如果SoapException的原因是Timeout,而不使用这里提到的消息(MSDN-Handle TimeoutException),是否有任何方法可以过滤掉。是否有任何字段可以指向基础异常的类型?

SoapException中存在不同的TimeoutException

试试这段代码,它可能会帮助您了解错误的原因:
PS:在catch() 中使用

string pageContent = new StreamReader(wex.Response.GetResponseStream()).ReadToEnd().ToString();
return pageContent;
相关文章:
  • 没有找到相关文章