WSSF (WCF) and Enterprise Library 3.1

Topics: General Discussion Forum, July and December Releases Forum
Jan 25, 2008 at 2:00 PM
Hi
This is not a post about health monitoring but my goal is to be able to monitor my WCF-service when put in production. What is best practice when it comes to Exception Handling and Logging when using WSSF with WCF?

I know this is a very general question that depends on many things and includes many things, but I also want a relative general answer. Can anybody come with some hints and guidelines on how YOU have set up your exception handling and logging so that others can get a kick-start on their way to make their system easy to monitor, track problems etc.

I would like many different approaches as possible here, so come on...!!!

RightCoder
Developer
Jan 29, 2008 at 9:50 PM
As a head start, you have "Exception Shielding" in EntLib that may give you a good guide on how to handle exceptions with logging capabilities in a secure way (that's why the shielding area) and then you also have the tracing features of WCF as well (quite documented in WCF docs et al.).
You can also find quickstars and examples of exception handling and logging in WSSFv2.
Jan 30, 2008 at 10:10 AM
Edited Jan 30, 2008 at 11:07 AM
Thanks Charly,
I thing I've got the overview of the EntLib, I know about the Exception Shielding and why you should use it. But I wonder what is done in practice by you pro's out there. Is it common practice to have a try-catch in every method of the service implementation so that every unhandled exception is catched and handeld by the Exception Shielding? Like this:

EntLibDemoEngine engine = new EntLibDemoEngine();

public string GetHelloWorldMessage()
{
try
{
return engine.HelloWorld();
}
catch(Exception ex)
{
if (ExceptionPolicy.HandleException(ex, "WCF Exception Shielding")) throw;
}
return null;
}

You have places in your code where you know an exception may occur, these places you put an try-catch and log with the LAB, but how do you handle all those other that you dont know about yet? Does anyone have some good experience here?

I may ask a bit detailed here but I think its a good discussion.... which more people would like to read and learn.
Developer
Jan 30, 2008 at 4:06 PM
As I mentioned on my first post in this thread, you can find some examples in the form of a Reference Implementation (WCF and ASMX) in the previous version of WSSF (v2).
There you will handle exceptions and logging in a completly cross-cutting or orthogonal way so you don't need to touch your service implementation layer. Simply find something like this:

    [ServiceContract(Namespace = "http://GlobalBank.CustomerProducts.ServiceContracts/2006/10", Name = "ICustomerFinder")]
    [ExceptionShielding("CustomerFinder")] // Enable exception shielding
    public interface ICustomerFinder
    {
        [OperationContract(Action = "FindCustomer")]
        [FaultContract(typeof(SystemFault))]                // System unhandled fault
        [FaultContract(typeof(CustomerFinderFaultContract))]
        CustomerFinderResponse FindCustomer(CustomerFinderRequest request);
    }
Then you will add the required wiring metadata in the web.config file of the host project and your service implementation operations won't have any extra code or additional things.
Feb 1, 2008 at 1:25 PM
Charly (my) Friend ;-) Great, thats what I really was looking for. Thanks.