zoukankan      html  css  js  c++  java
  • 【实用】C#测试web服务是否可用

    640?wx_fmt=jpeg


    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("不可用");

                }



  • 相关阅读:
    Python--初识函数
    Python中的文件操作
    Python中的集合
    Python中的编码和解码
    Python的关键字is和==
    Python中的字典
    Python中的列表和元组
    Python中几种数据的常用内置方法
    Python的编码
    python_while
  • 原文地址:https://www.cnblogs.com/hgmyz/p/12352172.html
Copyright © 2011-2022 走看看