Eric's Blog

Day to day experience in .NET
Welcome to Blogs @ IRM Sign in | Join | Help
 Search

Disclaimer

The content of this site is my own personal opinion and does not in any way represent my employer, it's subsideries or affiliates. These postings are provided "AS IS" with no warranties, and confer no rights.

This Blog

Exception Shielding

Exception Shielding is a design pattern that solves the problem, that a Web service should not disclose any information about the internal implementation of the service when an error occurs. In PAG's reference implementation of the Web Service Software Factory they have created a very elegant solution for this. But first let's go back one step and look what my code typically looks like today to enforce exception shielding.
 
    1 <WebMethod()> _
    2 Public Sub DoSomethingUseful()
    3     Try
    4         'Call internal code to do something useful
    5     Catch ex As Exception
    6         ExceptionPolicy.HandleException(ex, "Soap Policy")
    7         Throw
    8     End Try
    9 End Sub
 
For each and every method I catch Exception and hand it over to the Exception Handling Block in Enterprise Library. The policy is typically configured to ensure that a handler creates SoapExceptions without any stack information and other stuff that discloses the internal structure.
With the solution provided in the reference implementation mentioned above the code would look like this.
 
    1 <WebMethod()> _
    2 <ExceptionShielding("Soap Policy")> _
    3 Public Sub DoSomethingUseful()
    4     'Call internal code to do something useful
    5 End Sub
 
This saves me from writing 4 lines of code in each method. Or even better is that if you configure the soap extension ExceptionShieldingExtension in the web.config file you could even set the attribute at class level and save yourself another line of code for each method.
If you want to apply the attribute on each method it is not necessary to configure the ExceptionShieldingExtension in web.config, since the ExceptionShielding attribute inherits from SoapExtensionAttribute and therefore will the extension class be activated anyway by the framework.
 
Published den 14 september 2006 08:49 by ericqu

Comment Notification

If you would like to receive an email when updates are made to this post, please register here

Subscribe to this post's comments using RSS

Comments

 

The private life of Alex Thissen said:

You read it right. There is a very cheap way to shield exception information from an ASP.NET web service.
december 6, 2006 21:01
 

Erics Blog said:

While I was gone (three weeks in the US on vacation) pattern and practices have released Enterprise Library

april 23, 2007 22:35

Leave a Comment

(required) 
(optional)
(required) 
Submit
Powered by Community Server, by Telligent Systems