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.

2 Answers 2

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.

1
  • 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 :) Jun 15, 2012 at 6: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

2
  • cool, can you give an example of doing a ping to a wcf service? Jun 15, 2012 at 2:41
  • 1
    Create an operation on your contract called Ping that is takes no parameters and returns a bool of true. There's your ping. Jun 15, 2012 at 3:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.