WCF - 让客户检查服务可用性
我有一个客户端-服务器系统,双方都是我编写的,我想在服务器断开连接/死亡时将客户端置于“离线”状态,然后在服务器再次可用时自动将它们恢复“在线”状态。
对于第一部分,我侦听通道故障事件并通过将客户端设置为脱机来处理该事件。 然后我开始在服务器上调用“ping”服务(每 30 秒一次),如果它还活着,它只会返回一个布尔值。 一旦它处于活动状态,客户端就会获取布尔值并切换回在线状态。
这一切都有效,我遇到的问题是,当客户端调用 ping 服务并且服务器关闭时,没有发送响应(显然),最终,大约 2 分钟后,我得到一个端点未找到异常。 此时我已经尝试了 3-4 个以上的 ping,因此有 3-4 个异常正在酝酿。
我的问题是,如何更优雅地处理 ping 服务? 理想情况下,我想定期调用一项服务,让我知道它是否在线,并立即让我知道它是否不在线。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
怎么样:
这样,如果您处于“Ping 模式”,您可以快速得到响应(或超时),并且可以快速检测服务的可用性。
What about this:
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.