Throwing better SOAP exceptions

I'm fairly happy with my global unhandled exception handler for WinForms and console apps. I also successfully adapted a version of it for use in ASP.NET apps, where it interfaces with the Application_Error event in global.asax:


This is a companion discussion topic for the original blog entry at: http://www.codinghorror.com/blog/2004/08/throwing-better-soap-exceptions.html

a href="http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnservice/html/service09172002.asp"http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnservice/html/service09172002.asp/a

So what do you do when you deploy the Web service? You need to open up Web.config and edit the /configuration/system.web/customErrors/@mode attribute. By default, this attribute is set to RemoteOnly. The @mode attribute accepts two other values as well:

On
Off
The On setting tells ASP.NET not to add the stack trace information to any Faults. RemoteOnly causes the extra information to show up for clients on the same server and hides the information for remote users. When set to Off, the extra information shows up for all calls to the Web service. This is the same behavior you will see for Web pages. By setting the @mode attribute to On and throwing the same exception, I will get the following Fault instead:

I just set @mode attribute to “Off” while developing. Then when catching exceptions on the client side the exception is filled with method calls, line numbers, stack trace, etc.

Ah, interesting. I am familiar with the error setting for ASP.NET apps; I didn’t realize there was a similar setting specific to web services.

Download/order the WeFly247 application from Microsoft. (www.learn247.net)

They have made a quite elegant solution where they use the soap formatter (System.Runtime.Serialization.Formatters.Soap) to serialize and deserialize the exception.

I do not only want to see the exceptions when developing. I need to catch them with a “Application_Error” solution. Application_Error catches allmost all errors. aspx, ashx, master, and even 404 errors when the file does not exist.

I cannot find words for what I think of Microsoft after reading “there really is no good way to generically handle unhandled exception in .NET web services”.

Let us do it the windows way. Just wait for a new version and hope for the best.

Actually, I did find a way to handle web service exceptions globally. It’s documented in this CodeProject article…

http://www.codeproject.com/aspnet/ASPNETExceptionHandling.asp

Scroll down to “Unhandled Exceptions in ASP.NET Web Services”.

My application uses web services over remoting, and the details I add in the xmlNode of the SoapException do not show on the client side.
I resigned myself into sending all error info in one string.
Anyone has an idea of what may be wrong?
Thanks.

throw new SoapException(“Exception message here”, new XmlQualifiedName(“qualified name here, not empty !”));