views:

864

answers:

1

I am calling a web service from a C# forms based app.

ServReturnType obj = ServProxyClass(int i, int k);

I have the potential to get back an exception. The exception could be that the service didn't connect at all, that there was a failure on the receive, but the original message went, or anything in between. I then need to make a decision based on the exception thrown, either on the type, or the message, or both, as to do one of two actions next.

try
{    
     ServReturnType obj = ServProxyClass(int i, int k);
}
catch (WebException ex)
{
     DoAction1();
}
catch(SocketException ex)
{
     DoAction2();
}
catch(SoapException ex)
{
     DoAction1()
}

The issues is, my choice of subsequent actions depends on whether or not the first call made it to the server before failing. How can I find a list of all possible exceptions thrown, and what they might mean, as this is all code in the framework. I looked that MSDN docs, and saw that SoapHttpClientProtocol.Invoke can throw a SoapException, however there are methods called by this method that bubble up System.Net.WebExceptions. So I need a list of the whole call stack and what it can throw, and what that means.

Any ideas?

Update 1

Darin, your answer more or less confirms my suspicions that what I want doesn't really make sense. I have opted to do more detective work first, then use that to decide what to do next. Unfortunately in this case, since we are processing credit cards, it really matters what exactly has happened, and whether or not we sent data.

+2  A: 

The complete list of exceptions that can be thrown from a web service call is so vast that I really don't think that it is a good idea to test for every type of exception possible. In many cases it would be enough to catch for SoapException which could contain some business errors transmitted through the SOAP Fault Element and every other exception could be considered as a non handled error:

try
{    
    ServReturnType obj = ServProxyClass(int i, int k);
}
catch(SoapException ex)
{
    //Serialize and analyze the fault message from the exception to obtain more info.
    DoSomethingWithTheInfo();
}
catch(Exception ex)
{
    LogTheExceptionSoThatLaterYouKnowWhatHappened(ex);
    SayToTheUserThatSomethingTerriblyWrongHappened();
}

Here's a nice article explaining how to raise and handle SoapExceptions.

Darin Dimitrov