11

I have a client-server system, both sides written by me, and I would like to put the clients in an 'offline' state when the server disconnects/dies, and then automatically bring them back 'online' when the server is available again.

For the first part, I listen for channel faulted events and handle that by setting the client to offline. I then start calling a 'ping' service on the server (every 30 sec.) which just returns a bool if it is alive. Once it is alive the client gets the bool and switches back online.

This all works, the problem I am having is that when the client calls the ping service and the server is down, no response is sent (obviously) and eventually, after about 2mins I get an endpoint not found exception. By this time I have already tried 3-4 more pings and hence have 3-4 exceptions brewing.

My question is, how can I deal with the ping service more gracefully? Ideally I would like to periodically call a service that lets me know if it is online, and instantly lets me know if it is not.

Kiquenet
  • 14,494
  • 35
  • 148
  • 243
WillH
  • 2,086
  • 6
  • 23
  • 40
  • did you tried it? any sample code? Maybe ServiceContract with ***Ping*** method and test availability for `database connection, active directory, FileSystem, Email, Ftp, SFtp, SMS API`, etc – Kiquenet Jul 03 '18 at 13:13

1 Answers1

12

What about this:

  • if you detect a server disconnect, enter a "Ping" mode
  • in the "ping mode", you set the client's "sendTimeout" to something very short, e.g. something like 2 secs or so, since your call to the service's Ping method should be answered almost immediately
  • once your "Ping" worked successfully, you again re-create the client proxy and set the client's "sendTimeout" back to the original value (default is 1 minute - depends on what makes sense for you, 15 seconds, 30 seconds - whatever)

That way, if you're in "Ping mode", you get your responses (or timeouts) quickly and you can detect the availability of the service quickly.

Kiquenet
  • 14,494
  • 35
  • 148
  • 243
marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
  • Thanks Marc, great idea this is what I have done. I had completely forgotten that one can edit binding timeouts on the fly like this. – WillH Aug 06 '09 at 14:48
  • How to detect server is disconnected? – DoctorAV Feb 03 '16 at 10:57
  • @Ashutosh: if the server is disconnected, your call will fail with one of several possible errors ("not found" or "timeout" or othesr) – marc_s Feb 03 '16 at 12:03
  • sample code about `1) How to detect server is disconnected? 2) re-create the client proxy 3) set the client's "sendTimeout"` – Kiquenet Jul 03 '18 at 13:14