I have an application that consumes some WCF WebSocket service. Now if host closes connection, I get following exceptions:
- System.Net.Sockets.SocketException
- System.Net.WebSockets.WebSocketException
- System.ServiceModel.CommunicationException
Now I want to handle those exceptions in my client app and try to reconnect/inform a user etc. But how exactly catch those exceptions?
Maybe hook up to channel faulted event. I tried this:
context = new InstanceContext(this);
var endpointAddress = new EndpointAddress(ServerFullAddress);
context.Faulted += Channel_Faulted;
client = new ServiceName(context, "NetHttpBinding_ServiceName", endpointAddress);
But ChannelFaulted method never gets executed. How to hook up to this event properly, that this method will get executed when websocket is closed.
My other idea is to implement some global exception handler and catch those exceptions there? What do you think?