Search code examples
wcfconnection-timeouttimeoutexception

Catch WCF Timeout


Currently i have an issue regarding the WCF Timeout. The problem is how catch the error from WCF and catch it in global.asax ? I put try and catch in the business service, however it does not work. Appreciate much for your answer.

Regards


Solution

  • You should first determine what causes the time out exception - then handle the exception properly.

    If your service breaks (though I doubt a timeout falls under this category) you can catch it using the following in global.asax:

    serviceHost.Faulted += new EventHandler(serviceHost_Faulted);
    

    Note this isn't a good solution. Find the exact problem then use mocking frameworks (such as Moq) to simulate how your code (both client and service) will behave/recover in case your service takes too long to respond.