【实用】C#测试web服务是否可用


winform客户端经常需要调用webservice或者WCF进行数据交互,但是远程服务有可能不存在或者服务器不可用,客户端只能通过超时或者捕获到异常感知服务不可用。其实有一个COM借口可用快速的检测检测将要调用服务的状态。引用COM组件:Microsoft XML,v3.0,代码如下:

string url = "http://127.0.0.1/MySrv/MsgService.svc";

            XMLHTTP http = new XMLHTTP();

            try

            {

                http.open("GET", url, false, null, null);

                http.send(url);

                int status = http.status;

                if (status == 200)

                {

                    Console.WriteLine("成功");

                }

                else

                {

                    Console.WriteLine("不可用status:"+status.ToString());

                }

            }

            catch

            {

                Console.WriteLine("不可用");

            }



相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-12-09
  • 2021-10-23
  • 2022-01-19
猜你喜欢
  • 2021-08-04
  • 2021-06-30
  • 2022-12-23
  • 2022-12-23
  • 2021-11-19
相关资源
相似解决方案