检查 WCF Web 服务的可用性 [英] check the availability of the WCF Web Service
问题描述
我想通过 C# 代码检查 WCF Web 服务 i.c 服务是否可用.如何实现?
I want to check the availability of the WCF web service i.c service is up or down through the C# code. How to achieve that?
推荐答案
当你调用 Client.Open
时,如果它关闭,应该抛出一个你可以捕获的异常.
我更喜欢实现一个方法,该方法返回一个名为 Ping 的布尔值.代码基本上只是 return true;
所以它会尽快返回.在客户端,我调用它并捕获异常,如果我得到任何异常,则我知道 Web 服务已关闭.
您可以扩展该模式以执行 PingCheckDB 或 PingCheckX 之类的操作,它们可以执行假/示例测试运行,以便您根据可用内容启用/禁用客户端上的功能.
When you call Client.Open
if it is down that should throw an exception which you can trap.
What I prefer to do is implement a method which returns a boolean called Ping. The code basically just does return true;
so it returns as quickly as possible. On the client side I call it and trap exceptions, if I get any then I know the web service is down.
You can extend the pattern to do things like PingCheckDB or PingCheckX which can do a fake/sample test run so you enable/disable functionality on the client based on what is available.
这篇关于检查 WCF Web 服务的可用性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!