Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > Custom Exceptions with Web Services

Thread Tools

Custom Exceptions with Web Services

Chris Dunaway
Posts: n/a
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

<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:

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

Anyone know of a way to achieve this?

Thanks for any pointers


To send me an E-mail, remove the underscores and lunchmeat from my E-Mail
Reply With Quote
Shiv Kumar
Posts: n/a
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

Reply With Quote

Thread Tools

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 ASP .Net Web Services 4 03-31-2006 10:13 PM
Exceptions thrown by Web Services Water Cooler v2 ASP .Net Web Services 0 02-24-2006 11:45 AM
Throwing custom exceptions in web services using VS.Net Gian U. Uy ASP .Net Web Services 3 12-04-2003 07:06 PM
Custom exceptions -- inherit from exceptions.Exception? Paul Miller Python 3 11-12-2003 09:24 AM
throwing and handling exceptions in web services Lachlan James ASP .Net Web Services 1 07-17-2003 04:29 AM