How to wrap all SoapExceptions

  • Thread starter Rachit Samwalla
  • Start date
R

Rachit Samwalla

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!
 
B

Bruce Johnson [C# MVP]

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.
 
R

Rachit Samwalla

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.
 
B

Bruce Johnson [C# MVP]

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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,050
Latest member
AngelS122

Latest Threads

Top