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.
Asked
Active
Viewed 7,917 times
2 Answers
6
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.
-
yea I've used Discovery before .. but i don't think using discovery all connection live is a good idea.. because it searches for all servers ... and announcement wouldn't work if the connection lost (machine shutdown/cable unplugged) .. but i will check the IsAlive() thing and reply you .. thanks for your answer :) – Murhaf Sousli Jun 15 '12 at 06:04
3
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.

Community
- 1
- 1

Kevin DiTraglia
- 25,746
- 19
- 92
- 138
-
-
1Create an operation on your contract called `Ping` that is takes no parameters and returns a `bool` of `true`. There's your ping. – Jesse C. Slicer Jun 15 '12 at 03:13