Let me sketch the the situation. I have a Windows-Service (lets name it A) which calls a Web-Service (lets name him B). B calls upon different Web-Services himself. (lets call those Web-Services WS1,WS2,WS3)
Drawing:
//This is a Black Box (e.g. I can't change implementation)
+-----------------------------------------------+
| |
| ----> WS1 |
WindowsService A ----> | Webservice B ----> WS2 |
| ----> WS3 |
| |
+-----------------------------------------------+
From time to time exceptions may occur during the calls. Most exceptions should stop the executing of the program and notify the developer (Me). But when a Timeout occurs then Window-Service A should attempt a retry.
So I've written the following code:
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;
}
This code works brilliantly if the exception occurs in Web-Service B. Yet when the timeout occurs in WS1,WS2,WS3; I'm getting a SoapException.
Question:
Is there anyway to filter out if the cause of the SoapException was a Timeout without using the message as mentioned here (MSDN- Handle TimeoutException). Is there any field that could point to the type of the underlying exception?
Try this code, it might help you realize the cause of the error:
PS: Use it within
catch()