Client side error handling from webservices

Posts   
 
    
Maxus
User
Posts: 76
Joined: 04-Aug-2006
# Posted on: 25-Jul-2007 09:31:22   

Hi People,

As most people are aware when you use a webservice and an error is thrown, the error is extracted and then bundled into a field on the SoapException. Which means you cant use try..catches to catch specific error messages.

eg:

Web Service side:


    [WebMethod]
    public void ThrowTestException()
    {
         throw new DivideByZeroException();
    }

Client Side:


    public void TestWebService()
    {
         webService service = new webService()
        
         try
         {
               service.ThrowTestException();
         }
         catch(DivideByZeroException Ex)
         {
               // Never gets here.
         }
         catch(SoapException Ex)
         {
              // Goes here.
         }
    }

How are other people dealing with this? any tips of tricks? idealy I would like the proper exception on the client side, but I suspect that would break the abillity to interface with non dot net applications.

Thanks! A

Walaa avatar
Walaa
Support Team
Posts: 14950
Joined: 21-Aug-2005
Maxus
User
Posts: 76
Joined: 04-Aug-2006
# Posted on: 25-Jul-2007 11:23:52   

Hi Walaa,

thanks, I already saw both of those, though the ye olde google search, neither of them meet the requeirments of recieving an actual exception on the client side that you can catch, the only solution I've found so far is to use the soap formatter to add the exception to the soap message and throw it back and Deserialize it on the client. not a very elegant solution rage

Any other ideas?

Thanks! Alex

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39614
Joined: 17-Aug-2003
# Posted on: 27-Jul-2007 10:55:40   

It's natural: a webservice is a separate entity you call a method of and a webservice shouldn't bother YOU with an exception, because what happens if the webservice is a java app and you connect to it with a .net client? So the webservice should catch the exception and report it to the client in an information message. The client then should check what the information message is and act accordingly.

A webservice shouldn't be seen as a class library or a tier, it's a full application you communicate with (i.e. a vertical stack of tiers, not a single tier)

Frans Bouma | Lead developer LLBLGen Pro
jeffreygg
User
Posts: 805
Joined: 26-Oct-2003
# Posted on: 27-Jul-2007 21:35:01   

Otis wrote:

A webservice shouldn't be seen as a class library or a tier, it's a full application you communicate with (i.e. a vertical stack of tiers, not a single tier)

Amen. simple_smile