How to Detect a Diconnected Duplex Customer Survey

I watched the Tomek Janczuk Pub / sub sample using an HTTP poll of a duplex WCF channel , but I noticed that when the client disconnects, closing the browser, which the service does not notice on the next callback. I would expect an exception or say something that there was no longer an endpoint.

How do I know when a client has left to stop publishing this client?

+6
silverlight wcf
source share
4 answers

There seems to be one unsatisfactory, albeit simple, solution: if the client callback time, do not call it again.

On my system, I also performed a manual β€œcheck” check - every n seconds, when the server calls a method with no parameters on the callback channel for each registered client to see if the client is still there. I'm starting to wonder if this was really a good idea. I have a new problem when the callback timeout continues because I paused the client in the debugger.

+3
source share

Know for sure: impossible .

When the TCP connection is closed (under the HTTP call), a special TCP message is sent to the server - the FIN packet. Although HTTP is stateless, the underlying TCP connection is healthy, and by supporting it, the underlying TCP connection usually remains open. If the client is deleted, the TCP connection is closed and is usually sent to the server. But if he crashes or the network shuts down, he will not have time for this. So, in a word, you can never be sure.

Here for more information.

+5
source share

Its difficult, almost impossible (the reason for the limited capabilities of the duplex SL). we implemented a list of users in our service, and we added the IsDisconnected property and LastCommunicationTime as soon as the WCF service receives a timeout when it tries to add a message to the user Outgoing-Message-Queue and fails and throws a timeout exception. we mark "IsDisconnecte = true" and the next time we do not try to send a message to this user.

Another thread continues to look at it, and if it notices that the LastCommunicationTime value is exceeded by the time value and IsDisconnected = true, it removes the user from the list if the same user does not try to reconnect during this period of time (which we identify by its UserId) .

There are so many things we did manually to deal with this problem as it made the WCF service so busy.

+3
source share

I ran into this problem and created a thread that removes disconnected clients with the following code. It works fine, but it disconnects the disconnected client from the list of clients after 10-15 minutes (this was normal for me).

new Thread(new ThreadStart(() => { while (SilverlightClients != null) { lock (SilverlightClients) { SilverlightClients = SilverlightClients.Where(d => (d.Callback as IContextChannel).State != CommunicationState.Opened).ToList(); } Thread.Sleep(1000); } })) { Name = "Thread Remove Disconnected Clients" }.Start(); 
+1
source share

All Articles