How to wrap all SoapExceptions

Discussion in 'ASP .Net Web Services' started by Rachit Samwalla, Feb 3, 2005.

  1. Hi, I'm writing a fairly large web service and would like to be able to
    pass more complex exceptions to the client to make things easier to
    debug.

    I understand that if you throw a SoapExecption() with the Detail field
    populated with an XML node, this information gets passed to the client.

    What I wish is to write a global wrapper for all my web service
    functions that does the following:

    try {
    InvokeMethod();
    } catch (SoapException e) {
    // if its already a SoapException, just rethrow it.
    throw e;
    } catch (Exception e) {
    // for all other exceptions, wrap it in a soap exception and
    rethrow it.
    // The wrapper will include things like line number of failures,
    etc. in
    // the Detail node.
    throw new WrapperException(e);
    }

    What I cannot find is a place of putting this code such that I do not
    have to change every single function in my WebService. Nothing to
    override or anything. Only automated way I can think of is using a code
    generator or mucking with the Emit library, which is less than ideal.

    I'm sure others have faced this problem, but I have searched everywhere
    and can't find anything.

    Thanks!
     
    Rachit Samwalla, Feb 3, 2005
    #1
    1. Advertising

  2. You're having trouble, because such a place really doesn't exist. The other
    alternatives (SoapExtensions and HttpHandlers) are either inconvenient or
    will not contain enough information. The pattern in your example is the best
    solution that I have seen.

    "Rachit Samwalla" wrote:

    >
    > Hi, I'm writing a fairly large web service and would like to be able to
    > pass more complex exceptions to the client to make things easier to
    > debug.
    >
    > I understand that if you throw a SoapExecption() with the Detail field
    > populated with an XML node, this information gets passed to the client.
    >
    > What I wish is to write a global wrapper for all my web service
    > functions that does the following:
    >
    > try {
    > InvokeMethod();
    > } catch (SoapException e) {
    > // if its already a SoapException, just rethrow it.
    > throw e;
    > } catch (Exception e) {
    > // for all other exceptions, wrap it in a soap exception and
    > rethrow it.
    > // The wrapper will include things like line number of failures,
    > etc. in
    > // the Detail node.
    > throw new WrapperException(e);
    > }
    >
    > What I cannot find is a place of putting this code such that I do not
    > have to change every single function in my WebService. Nothing to
    > override or anything. Only automated way I can think of is using a code
    > generator or mucking with the Emit library, which is less than ideal.
    >
    > I'm sure others have faced this problem, but I have searched everywhere
    > and can't find anything.
    >
    > Thanks!
    >
    >
     
    Bruce Johnson [C# MVP], Feb 3, 2005
    #2
    1. Advertising

  3. Thanks for the response.

    I kind of figured there was no way to do this, since I looked carefully
    at the complete stack trace while in a web method and found no good
    class I could override and inject my wrapper.

    This is fairly surprising. I'd think quite a few people would want this
    and the interface designers would have forseen this.
     
    Rachit Samwalla, Feb 3, 2005
    #3
  4. I hear what you're saying and agree. Anytime that I have been designing a
    production grade web service, those silly administrators keep wanting metrics
    and exception logging. The b**tards. ;) And, like I said, the pattern you
    described seems to be the best way at the moment.

    Even with something like a SoapExtension, you are still getting

    "Rachit Samwalla" wrote:

    > Thanks for the response.
    >
    > I kind of figured there was no way to do this, since I looked carefully
    > at the complete stack trace while in a web method and found no good
    > class I could override and inject my wrapper.
    >
    > This is fairly surprising. I'd think quite a few people would want this
    > and the interface designers would have forseen this.
    >
    >
     
    Bruce Johnson [C# MVP], Feb 3, 2005
    #4
    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. Aaron Fude

    To wrap or not to wrap?

    Aaron Fude, May 8, 2008, in forum: Java
    Replies:
    12
    Views:
    724
    Chronic Philharmonic
    May 10, 2008
  2. carl
    Replies:
    0
    Views:
    106
  3. cj
    Replies:
    0
    Views:
    249
  4. Art Werschulz

    Text::Wrap::wrap difference

    Art Werschulz, Sep 22, 2003, in forum: Perl Misc
    Replies:
    0
    Views:
    259
    Art Werschulz
    Sep 22, 2003
  5. Art Werschulz

    Text::Wrap::wrap difference

    Art Werschulz, Sep 24, 2003, in forum: Perl Misc
    Replies:
    1
    Views:
    262
    Anno Siegel
    Sep 25, 2003
Loading...

Share This Page