WCF Full Duplex Handle Client Disconnection
Is there any way for me to detect client disconnection from my service? I only get开发者_如何学Go the chance to know if a certain client is disconnected on try-catch method which is not a very good way to do it. I don't want to create a timer for each new client that connects on my service just to monitor its last transaction.
No, there is no simple or elegant way to detect client disconnection. It would be a nice environment if, when the client shut down or crashed, the service received a "ClientTerminated" event. However, this behaviour simply doesn't fit with a message-based architecture.
A not-so elegant solution is to periodically ping the client with a callback method, and see if this call times out.
Alternatively, if you are using PerSession instancing, you can set the inactivityTimeout to a short value (say, one minute as opposed to the default 10), and on the client side use a timer to periodically invoke an empty method on the server.
See this question for a similar discussion.
精彩评论