0

让我勾勒一下情况。我有一个Windows 服务(让我们命名A,其中calls一个 Web 服务(让他命名BB自己调用不同的 Web 服务。(让我们称这些 Web服务WS1,,,WS2WS3

绘画:

                       //This is a Black Box (e.g. I can't change implementation)
                       +-----------------------------------------------+
                       |                                               |
                       |                  ----> WS1                    |
WindowsService A ----> |   Webservice B   ----> WS2                    |
                       |                  ----> WS3                    |
                       |                                               |
                       +-----------------------------------------------+

通话期间可能会不时发生异常。大多数异常应该停止程序的执行并通知开发人员(我)。但是当 aTimeout发生时,Window-ServiceA应该尝试 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-Service 中,B此代码将非常有效。然而,timeoutWS1, WS2, WS3; 我得到一个SoapException.

问题:如果没有使用此处提到的消息(MSDN-Handle TimeoutException) ,是否有
过滤掉的原因。是否有任何字段可以指向底层异常的类型?SoapExceptionTimeout

4

1 回答 1

0

试试这个代码,它可能会帮助你了解错误的原因:
PS:在里面使用它catch()

string pageContent = new StreamReader(wex.Response.GetResponseStream()).ReadToEnd().ToString();
return pageContent;
于 2014-10-15T07:37:51.670 回答