Reputation: 1367
I have a WCF service and number of clients which retrieve information about credentials. I want to monitor list of these clients and detect if some of the clients suddenly die (due to connection loss or application crash or something) What is the best way to do this ?
As I understand duplex communication contract would not be the best solution.
Upvotes: 0
Views: 811
Reputation: 5312
There is really no good way to do this apart from catching a CommunicationException. You can also look at the IClientChannel events to monitor what happens with the connection.
client.InnerChannel.Closed += OnChannelClosed;
client.InnerChannel.Opening += OnChannelOpening;
client.InnerChannel.Opened += OnChannelOpened;
client.InnerChannel.Closing += OnChannelClosing;
client.InnerChannel.Faulted += OnChannelFaulted;
client.InnerChannel.UnknownMessageReceived += OnChannelUnknownMessageReceived;
Upvotes: 1
Reputation: 15569
One way to do this would be to implement a "heartbeat". To do this, keep a collection of clients. Have the client send a simple message with minimal information (a heartbeat message).
On the server side, put an eviction process in place that periodically looks through the list of clients to see if there are any that have gone "stale" (i.e. you haven't received a heartbeat in a while).
Upvotes: 2