• 调用http://WebXml.com.cn/的webservice获取手机号段信息


    反正要使用wsdl4j.jar,axis.jar等一些jar包

    soap协议规范

    SOAP 1.1

    以下是 SOAP 1.2 请求和响应示例。所显示的占位符需替换为实际值。

    POST /WebServices/MobileCodeWS.asmx HTTP/1.1
    Host: www.webxml.com.cn
    Content-Type: text/xml; charset=utf-8
    Content-Length: length
    SOAPAction: "http://WebXml.com.cn/getMobileCodeInfo"
    
    <?xml version="1.0" encoding="utf-8"?>
    <soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
      <soap:Body>
        <getMobileCodeInfo xmlns="http://WebXml.com.cn/">
          <mobileCode>string</mobileCode>
          <userID>string</userID>
        </getMobileCodeInfo>
      </soap:Body>
    </soap:Envelope>
    HTTP/1.1 200 OK
    Content-Type: text/xml; charset=utf-8
    Content-Length: length
    
    <?xml version="1.0" encoding="utf-8"?>
    <soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
      <soap:Body>
        <getMobileCodeInfoResponse xmlns="http://WebXml.com.cn/">
          <getMobileCodeInfoResult>string</getMobileCodeInfoResult>
        </getMobileCodeInfoResponse>
      </soap:Body>
    </soap:Envelope>

     

    SOAP 1.2

    以下是 SOAP 1.2 请求和响应示例。所显示的占位符需替换为实际值。

    POST /WebServices/MobileCodeWS.asmx HTTP/1.1
    Host: www.webxml.com.cn
    Content-Type: application/soap+xml; charset=utf-8
    Content-Length: length
    
    <?xml version="1.0" encoding="utf-8"?>
    <soap12:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap12="http://www.w3.org/2003/05/soap-envelope">
      <soap12:Body>
        <getMobileCodeInfo xmlns="http://WebXml.com.cn/">
          <mobileCode>string</mobileCode>
          <userID>string</userID>
        </getMobileCodeInfo>
      </soap12:Body>
    </soap12:Envelope>
    HTTP/1.1 200 OK
    Content-Type: application/soap+xml; charset=utf-8
    Content-Length: length
    
    <?xml version="1.0" encoding="utf-8"?>
    <soap12:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap12="http://www.w3.org/2003/05/soap-envelope">
      <soap12:Body>
        <getMobileCodeInfoResponse xmlns="http://WebXml.com.cn/">
          <getMobileCodeInfoResult>string</getMobileCodeInfoResult>
        </getMobileCodeInfoResponse>
      </soap12:Body>
    </soap12:Envelope>

     

    HTTP GET

    以下是 HTTP GET 请求和响应示例。所显示的占位符需替换为实际值。

    GET /WebServices/MobileCodeWS.asmx/getMobileCodeInfo?mobileCode=string&userID=string HTTP/1.1
    Host: www.webxml.com.cn
    
    HTTP/1.1 200 OK
    Content-Type: text/xml; charset=utf-8
    Content-Length: length
    
    <?xml version="1.0" encoding="utf-8"?>
    <string xmlns="http://WebXml.com.cn/">string</string>

     

    HTTP POST

    以下是 HTTP POST 请求和响应示例。所显示的占位符需替换为实际值。

    POST /WebServices/MobileCodeWS.asmx/getMobileCodeInfo HTTP/1.1
    Host: www.webxml.com.cn
    Content-Type: application/x-www-form-urlencoded
    Content-Length: length
    
    mobileCode=string&userID=string
    HTTP/1.1 200 OK
    Content-Type: text/xml; charset=utf-8
    Content-Length: length
    
    <?xml version="1.0" encoding="utf-8"?>
    <string xmlns="http://WebXml.com.cn/">string</string>

     具体调用函数

    public static String[] GetMobileMarkByWebService(String mobile7) {
      String[] mobileInfos = new String[] {};
      try {

      //调用webservice的地址
       String endPoint = "http://www.webxml.com.cn/WebServices/MobileCodeWS.asmx";
       Service service = new Service();
       Call call = (Call) service.createCall();
       call.setTargetEndpointAddress(new URL(endPoint));

      //调用webservice方法,必须这样调用该方法,是根据soap协议里的方法声明
       call.setOperationName(new QName("http://webxml.com.cn/getMobileCodeInfo)); 

    //webservice里method的参数,必须这样定义,否则必然出错

       call.addParameter(new QName("http://WebXml.com.cn/", "mobileCode"),XMLType.XSD_STRING, ParameterMode.IN);
       call.addParameter(new QName("http://WebXml.com.cn/", "userID"),XMLType.XSD_STRING, ParameterMode.IN);
       call.setReturnType(XMLType.XSD_STRING);
       call.setUseSOAPAction(true);
       call.setSOAPActionURI("http://WebXml.com.cn/getMobileCodeInfo");
       String result = (String) call.invoke(new Object[] { mobile7, "" });
       String[] infos = result.split(":", 2);
       if (infos.length == 2) {
        mobileInfos = infos[1].split(" ", 3);
       }
      } catch (Exception e) {
       e.printStackTrace();
      }
      return mobileInfos;
     }

    唯一不爽的就是这个webservice只能免费使用50次每天每IP。

  • 相关阅读:
    C#中调用DTS
    经典问题:向setTimeout传递函数参数
    C#.NET 中的类型转换
    SQL语句导入导出大全 (转载)
    js脚本defer的作用
    [转]使用 Java API 处理 WebSphere MQ 大消息
    WideCharToMultiByte 宽字节转换为多字节
    [原].NET数据库开发中请注意区域时间格式
    输出页眉和页脚的简单HTTP模块实践
    浅析ASP.NET HTTP Module
  • 原文地址:https://www.cnblogs.com/zsxfbj/p/1748561.html
Copyright © 2020-2023  润新知