User999999
User999999

Reputation: 2520

Distinct TimeoutException from SoapException

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?

Upvotes: 0

Views: 848

Answers (1)

SanyTiger
SanyTiger

Reputation: 666

Try this code, it might help you realize the cause of the error:
PS: Use it within catch()

string pageContent = new StreamReader(wex.Response.GetResponseStream()).ReadToEnd().ToString();
return pageContent;

Upvotes: 0

Related Questions