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.