Exception Shielding eating Fault Contracts

Topics: General Discussion Forum, Service Factory Modeling Edition Forum
Apr 2, 2008 at 10:09 PM
I have implemented Exception Shielding using Ent Lib 3.1 with WSSF Modeling Edition VS 2008. The Exception Shielding is working great but a little to great. Not only is it shielding Sytem.Exception but also shielding all my Fault Contracts. Using WCF Exception Shielding on Exception Type System.Exception. Have an Operation called Get() which has two FaultContracts associated with it.
GetResponse Get(GetRequest request);
SystemFault is used in the Fault Contract Exception Handler to map all System.Exception to the Fault Contract SystemFault, where SystemFault contains a member called ID of type Guid.
My problem is when I go to throw my Fault Contract
CriteriaNotSuppliedFault oFault = new CriteriaNotSuppliedFault();
oFault.Message = "Please enter a City & State or a ZIP Code.";
throw new System.ServiceModel.FaultException<CriteriaNotSuppliedFault>(oFault);
It gets ExceptionShielded. User ends up with
catch (System.ServiceModel.FaultException<ListingManagementProxy.SystemFault> systemFault)
WriteMessage("SystemFault:" + "An error has occurred while consuming Web service. ErrorId: " + systemFault.Detail.ID);
Anyone have any idea why Fault Contracts are being Shielded?
Apr 4, 2008 at 3:29 AM
Notice that you should configure shielding (in config file) in a way that will not intercept your applicaiton fault and let it pass through back to your client.
Here is an example, inside your :

      <add name="WCF Exception Shielding">
               ... some other types here like the your SystemFault
               <add name="CriteriaNotSuppliedFault"
                        type="CriteriaNotSuppliedFault, yourAsm"
Apr 4, 2008 at 11:51 AM
I believe I have resolved the issue. My config file looked like this:
<add name="WCF Exception Shielding">
<add type="System.Exception, mscorlib, Version=, Culture=neutral, PublicKeyToken=b77a5c561934e089"
postHandlingAction="ThrowNewException" name="Exception">
<add logCategory="General" eventId="100" severity="Error" title="Listing Management Services"
formatterType="Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.TextExceptionFormatter, Microsoft.Practices.EnterpriseLibrary.ExceptionHandling, Version=, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"
priority="0" type="Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.Logging.LoggingExceptionHandler, Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.Logging, Version=, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"
name="Logging Handler" />
<add faultContractType="Svc.WCF.FaultContracts.SystemFault, Svc.WCF.FaultContracts, Version=, Culture=neutral, PublicKeyToken=null"
exceptionMessage="An error has occurred while consuming this service. Please contact your system administrator for more information."
type="Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.WCF.FaultContractExceptionHandler, Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.WCF, Version=, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"
name="Fault Contract Exception Handler">
<add source="{Guid}" name="ID" />

To correct the problem I added the following Exception Type:
<add type="System.ServiceModel.FaultException, System.ServiceModel, Version=, Culture=neutral, PublicKeyToken=b77a5c561934e089"
postHandlingAction="NotifyRethrow" name="FaultException" />

So now the Exception Policy "WCF Exception Shielding" has two Exception Types "System.Exception" and "System.ServiceModel.FaultException" instead of just the one "System.Exception" . This seems to let the Fault Contracts through.
Apr 4, 2008 at 11:53 AM
Is this what you suggested? Thanks for your help!

Also how do you get your code examples to appear in that little box, properly formatted?
Apr 4, 2008 at 3:55 PM
In that case, then any exception that derives from FaultException will be bypassed and sent directly to the client. That's fine as long as this is what you expect.
Regarding the formatted code, just enclose your code section with;


Without the quotes.