简体   繁体   中英

WCF Full Duplex Handle Client Disconnection

Is there any way for me to detect client disconnection from my service? I only get 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM