System Exceptions in WCF Shielding

Topics: Exception Handling Application Block, General discussion
Feb 1, 2010 at 1:40 PM


I am new to WCF Exception shielding, I have few doubts.

1. How are System Exceptions-- Invalid operation , null reference -- handled in the WCF Exception shielding? Do they also need a data contract or can just be re thrown?

2. If exceptions are thrown from a WCF, should it have a data contract in each scenario or, can the same data contract be used for all sorts of exceptions?

All I want to achieve is, to handle the exceptions on client side ( which uses WCF services) and depending on the type of exception, to proceed further.

For example: If an User is trying to purchase a product which is not currently available, "Out of stock" message should be displayed; if the User is trying to view the empty basket, “Empty basket” message should be displayed.

Feb 2, 2010 at 1:22 AM

1.  The point of shielding exceptions is to hide sensitive information from the client like the detailed stack trace which can provide information on how your service inner workings.  It's best that you provide a fault contract for those exceptions and throw them as FaultException<YourFaultContract> rather than just rethrowing them.

2.  It's both possible to use different contracts for different scenarios or using a single one.  But I think if you're going to use EntLib's EHAB, you'll have more control on the error message you want to use for each type of exception if you have different contracts.


Sarah Urmeneta
Global Technology & Solutions
Avanade, Inc.