让我描绘一下情况。我有一个 Windows服务(让我们命名为A
) calls
一个Web服务(让他给他命名B
) 。 B
在不同的 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
出现时,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-Service B
中,则此代码可以运行。然而,当timeout
,WS1
,WS2
中出现WS3
时;我得到SoapException
。
问题:
无论如何,如果SoapException
的原因是Timeout
而没有使用此处提到的消息(MSDN- Handle TimeoutException),则会过滤掉。是否有任何字段可以指向基础异常的类型?
答案 0 :(得分:0)
试试这段代码,它可能会帮助您了解错误原因:
PS:在catch()
string pageContent = new StreamReader(wex.Response.GetResponseStream()).ReadToEnd().ToString();
return pageContent;