Ask a questionAsk a question
 

AnswerHandling Exceptions in WCF Environment

  • Wednesday, November 04, 2009 11:46 AMDekkkart Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    Hi all,
    We have an n-tier application structure build with the help of WCF. Our Hosting Service is an Windows Service for production and a Console application witch starts all the services for development.

    The problem is that when an UNHADLED Exception rases the Hosting Service stops and someone have to turn it on again.

    I want when an unhandled exception rases:
    1. to handle it and to show an appropriate message on the presenter side
    2. not to stop my service or at least to restart it.

    What I've tried till now:
    1. host.Faulted += ServiceHost_Faulted; If a service faults that's enough too handle the exception

    2. AppDomain currentDomain = AppDomain.CurrentDomain;

    currentDomain.UnhandledException +=

    new UnhandledExceptionEventHandler(GlobalExceptionHandler);

    in the Main method ot OnStart() if service

    The problem is that there could be exceptions in the Data Access Layer or Business Logic which are not in a try catch block and are not handled by those two methods I mentioned above.


    My Question is: Is there a global way to handle all unhandled exception in every tier of the application?

Answers

  • Wednesday, November 04, 2009 12:04 PMMahesh Sabnis Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Answer
    Hi,

     
    Have you tried to use Exception Handling Application block of Enterprise library 4.2? If not try it out for every layer.
    Also what you can do is write a custom exception and configure this using Fault contract in WCF service. Using This way you will be able to customize the exception message to the client application. Please try this out This shpold work as far as exception handling is concerned.


    Mahesh Sabnis
    • Marked As Answer byDekkkart Thursday, November 05, 2009 11:27 AM
    •  

All Replies

  • Wednesday, November 04, 2009 12:04 PMMahesh Sabnis Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Answer
    Hi,

     
    Have you tried to use Exception Handling Application block of Enterprise library 4.2? If not try it out for every layer.
    Also what you can do is write a custom exception and configure this using Fault contract in WCF service. Using This way you will be able to customize the exception message to the client application. Please try this out This shpold work as far as exception handling is concerned.


    Mahesh Sabnis
    • Marked As Answer byDekkkart Thursday, November 05, 2009 11:27 AM
    •  
  • Thursday, November 05, 2009 11:27 AMDekkkart Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    Hi Mahesh,

    I use some of the application blocks of Enterprise Library, but didn't come up with Exception Handling block. You gave me very good reminder. Thanks a lot. I'll try it and give some feedback when finished.