how to detect WCF service shutdown or disconnect from client?
I'm building a WCF service,after a client connects to this service,when the service disconnect, the client doesn't notice that, and it doesn't fire any action, i would like to close client form whenever the connection lost,so how would i detect WCF service disconnect or shutdown from client side.
A simple approach is the client will call a simple method in service called IsAlive() just returns true as described in this thread.
There is another way you could achieve this using the new Discovery/Announcement features that comes with WCF 4. Though I haven't tried but this feature helps you to make the service notify the client if it gets into offline/shutdown.
Here is an example post.
You can google "WCF announement service" and you'll get some good reference materials.
You should probably just set up a timer that will continually ping the server, and if the fails, fire an event that the service is no longer available.
This answer also has some good suggestions.