WCF - 让客户检查服务可用性

发布于 2024-07-30 03:59:40 字数 417 浏览 6 评论 0原文

我有一个客户端-服务器系统,双方都是我编写的,我想在服务器断开连接/死亡时将客户端置于“离线”状态,然后在服务器再次可用时自动将它们恢复“在线”状态。

对于第一部分,我侦听通道故障事件并通过将客户端设置为脱机来处理该事件。 然后我开始在服务器上调用“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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

沙沙粒小 2024-08-06 03:59:40

怎么样:

  • 如果您检测到服务器断开连接,请
  • 在“ping模式”中输入“Ping”模式,将客户端的“sendTimeout”设置为非常短的时间,例如2秒左右,因为您对服务的调用 Ping 方法应该几乎立即得到答复
  • 一旦您的“Ping”成功, ,您再次重新创建客户端代理并将客户端的“sendTimeout”设置回原始值(默认为 1 分钟 - 取决于对您有意义的时间,15秒、30 秒 - 随便)

这样,如果您处于“Ping 模式”,您可以快速得到响应(或超时),并且可以快速检测服务的可用性。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文