Custom Exceptions with Web Services

Discussion in 'ASP .Net' started by Chris Dunaway, Jan 13, 2004.

  1. 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.
    Chris Dunaway, Jan 13, 2004
    #1
    1. Advertising

  2. Chris Dunaway

    Shiv Kumar Guest

    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
    Shiv Kumar, Jan 13, 2004
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Paul Miller
    Replies:
    3
    Views:
    1,009
    Alex Martelli
    Nov 12, 2003
  2. Lachlan James

    throwing and handling exceptions in web services

    Lachlan James, Jul 14, 2003, in forum: ASP .Net Web Services
    Replies:
    1
    Views:
    111
    Lachlan James
    Jul 17, 2003
  3. Gian U. Uy

    Throwing custom exceptions in web services using VS.Net

    Gian U. Uy, Nov 30, 2003, in forum: ASP .Net Web Services
    Replies:
    3
    Views:
    163
    Gian U. Uy
    Dec 4, 2003
  4. Water Cooler v2

    Exceptions thrown by Web Services

    Water Cooler v2, Feb 24, 2006, in forum: ASP .Net Web Services
    Replies:
    0
    Views:
    99
    Water Cooler v2
    Feb 24, 2006
  5. John
    Replies:
    4
    Views:
    413
Loading...

Share This Page