Exception Shielding with fault contract handler driving me nuts!

Jul 12, 2009 at 4:45 PM

Hi, I am trying to implement exception shileding for my service using the Exception Handling Application Block.

I have created a DataContract with my custom FaultException Class, declared the ExceptionShielding("PolicyName") directive in the ServiceContract decleration and declared a faultcontract for the OperationContract.

Using the Enterprise Library Configuration Editor, I have included the Server Exception Policy in my app.config, which maps an SQLException to my custom FaultException Class (SQLException->ThrowNewException->Fault Contract Exception Handler wich points to my custom fault contract and has the proper Property Mappings).

The problem is that when a SQLExpetion is raised at the service, the client always receives a CommunicationException ('An error has occurred while consuming this service. Please contact your administrator for more information. Error ID: blah-blah') and NOT a Faultexception<CustomException>!

I have tried EVERYTHING I can think of. It's like the Shileding totally ignores the app.config!

Anybody, please help!

Jul 12, 2009 at 10:37 PM
Edited Jul 12, 2009 at 10:41 PM

Look at the exception message you recieve a little bit harder..

There is a good chance your fault exception is embeded at a lower level in the exception?  So check all the properties in the exception!

Also - just give some thought to puting your validation up at the data Access level rather than the Sevice Contract level.   i.e. Validate the data just prior to saving it.  That way if you use the data access objects for some other purpose the validation is already built in.


Jul 12, 2009 at 11:58 PM

Silly me, I had forgotten to remove the constructor I used before for the custom exception class. so I suppose the fault I was receiving was the "no valid constructor" the framework was receiving while trying to instanciate my class... After removing it, it works fine.