zoukankan      html  css  js  c++  java
  • Java调用WebService实例

        /**
         * 检查QQ是否在线
         */
        @Test
        public void qqCheckOnline(){
            String endpoint = "http://www.webxml.com.cn/webservices/qqOnlineWebService.asmx?wsdl";
            Service service = new Service();
            try {
                Call call = (Call) service.createCall();
                call.setTargetEndpointAddress(new java.net.URL(endpoint));
                call.setSOAPActionURI("http://WebXml.com.cn/qqCheckOnline");
                call.setOperationName(new QName("http://WebXml.com.cn/", "qqCheckOnline"));
                call.addParameter(new QName("http://WebXml.com.cn/", "qqCode"),
                        org.apache.axis.encoding.XMLType.XSD_STRING, ParameterMode.IN);
                call.setReturnType(XMLType.SOAP_STRING);
                System.out.println(call.invoke(new Object[]{"160468630*"}));
            }catch (Exception e) {
                e.printStackTrace();
            }
    
        }
    
        /**
         * 获取天气
         */
        @Test
        public void getWeather(){
            String endpoint = "http://ws.webxml.com.cn/WebServices/WeatherWS.asmx?wsdl";
            Service service = new Service();
            try {
                Call call = (Call) service.createCall();
                call.setTargetEndpointAddress(new URL(endpoint));
                call.setSOAPActionURI("http://WebXml.com.cn/getWeather");
                call.setOperationName(new QName("http://WebXml.com.cn/", "getWeather"));
                call.addParameter(new QName("http://WebXml.com.cn/", "theCityCode"),
                        org.apache.axis.encoding.XMLType.XSD_STRING, ParameterMode.IN);
                call.addParameter(new QName("http://WebXml.com.cn/", "theUserID"),
                        org.apache.axis.encoding.XMLType.XSD_STRING, ParameterMode.IN);
                call.setReturnType(XMLType.SOAP_VECTOR);
                System.out.println(call.invoke(new Object[]{"",""}));
            }catch (Exception e) {
                e.printStackTrace();
            }
    
        }
    
  • 相关阅读:
    php smarty使用..
    深圳面试!
    jQuery 源码分析..
    jQuery 使用技巧!!!
    TOMCAT 访问过程...
    准备使用Delphi调用WCF
    Delphi 中Format的字符串格式化使用说明(转载http://hi.baidu.com/test__123/blog/item/e3bba1599d717a2d2834f092.html)
    电脑启动程序自动启动
    判断输入字符串是否等效Int32位数字的两种方法
    vs2005 快捷键
  • 原文地址:https://www.cnblogs.com/guoyx/p/15608105.html
Copyright © 2011-2022 走看看