tags:

views:

18

answers:

1

On the server side there is IErrorHandler etc.

On the client, exceptions are thrown when you call the methods on the channel.

Is there a way to intercept the exceptions on the client before they are thrown during invocation of method?

A: 

No, you cannot intercept the exceptions before they happen.... or what are you really trying to achieve??

What you need to do on the client side is basically just defensive programming: put your service calls into try...catch... blocks and handle the exceptions you can (and want to) handle:

MyServiceClient client = new MyServiceClient();

try
{
    client.MakeYourCall();
}
catch(EndpointNotFoundException ex)
{
   // tell the user the endpoint doesn't exist
}      
catch(CommunicationException ex)
{
   // catch the WCF base exception to handle all other WCF related issues, if needed
}      
catch(TimeoutException ex)
{
   // tell the user a timeout occured
}      

All WCF related exceptions are descendants of the base CommunicationException class (except, as I recently learned: QuotaExceededException) - catch the more specific ones if you can react to them.

And then there's the system-wide TimeoutException which might also be something you want to catch (it's not WCF specific, so it doesn't descend from CommunicationException)

marc_s
I want a centralised system to manage all of the communication/timeout exceptions, handle reconnecting etc. I will have various classes that all share the same channel. I want to have one TCP connection being used by all the components in my application. I dont want to have each one having logic to handle exceptions, I just want them to catch any exceptions and go into a 'comms error' mode. The the centralised monitoring of the channel will correct the problem if possible (e.g. reconnect), then notify all the components they can try again (with new channel). WCF seems shit for this so far :)
Schneider