3

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.

Murhaf Sousli
  • 11,806
  • 20
  • 109
  • 179

2 Answers2

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.

Community
  • 1
  • 1
VJAI
  • 31,095
  • 22
  • 99
  • 157
  • 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.

WCF - have client check for service availability

Community
  • 1
  • 1
Kevin DiTraglia
  • 25,012
  • 19
  • 91
  • 135