PC Review


Reply
Thread Tools Rate Thread

Custom Exceptions with Web Services

 
 
Chris Dunaway
Guest
Posts: n/a
 
      13th Jan 2004
I'm creating a Web service and a Windows Forms application to consume it.
My question is about throwing a custom exception inside the WebService.
Can that be done, and can the custom web service be handled in the Windows
Forms app?

For example, suppose in my WebService, I have the following exception
class:

'\\\\\
<Serializable()> _
Public Class WebServiceException
Inherits ApplicationException <<<<<<< Is this correct?

'Code for exception class here

End Class
../////

And then within my web method:

'\\\\\
<WebMethod()> _
Public Sub SomeWebMethod()

If SomeCondition Then
Throw New WebServiceException
End If
End Sub
'/////


On the Windows Forms client, I can only trap for generic exceptions not my
custom exception type:

Try
WebService.SomeWebMethod
Catch ex As WebServiceException <<<<<<<<< This doesn't work
'Handle it
End Try


Anyone know of a way to achieve this?

Thanks for any pointers

--
Chris

To send me an E-mail, remove the underscores and lunchmeat from my E-Mail
address.
 
Reply With Quote
 
 
 
 
Shiv Kumar
Guest
Posts: n/a
 
      13th Jan 2004
This seems to be a limitation of .NET SOAP implementation. Ideally things
should happen the way you're expecting (like they do in other SOAP
implementations), especially if both sides are built by you.

However, typically you should derive your SOAP exceptions from
System.Web.Services.Protocols.SoapException. This class has additional
properties you can set such as Actor, Code, Detail, Message when you throw
the exception at the server end.

Either ways, a SOAPException is raised on the client and you are left with
parsing the properties of this exception to figure out what really happened.
To go a step further, you could have a class that knows how to parse the
soap fault and raise the actual exception on the client provided, the client
is aware of that exception as well. Or maybe you could use SOAP Extensions
and do it that way.
--
Shiv R. Kumar
http://www.matlus.com


 
Reply With Quote
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
How .NET web services client handles exceptions from Java web services? John Microsoft Dot NET 0 9th Mar 2006 07:47 AM
Exceptions thrown by Web Services Water Cooler v2 Microsoft Dot NET Framework 4 25th Feb 2006 05:58 AM
Exceptions thrown by Web Services Water Cooler v2 Microsoft C# .NET 2 25th Feb 2006 05:58 AM
Exceptions and Web services xxxxyz@abv.bg Microsoft C# .NET 1 22nd Mar 2005 09:39 AM
Custom Exceptions with Web Services Chris Dunaway Microsoft Dot NET 1 13th Jan 2004 10:35 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 09:14 PM.