`

axis2 读取天气

阅读更多
package com.wether.test;

import org.apache.axiom.om.OMAbstractFactory;
import org.apache.axiom.om.OMElement;
import org.apache.axiom.om.OMFactory;
import org.apache.axiom.om.OMNamespace;
import org.apache.axiom.soap.SOAP11Constants;
import org.apache.axis2.Constants;
import org.apache.axis2.addressing.EndpointReference;
import org.apache.axis2.client.Options;
import org.apache.axis2.client.ServiceClient;
//  http://hi.baidu.com/e_ville/blog/item/f6529fa1a6616a8e471064a3.html
/**
* 测试WebService
* @author
* @history 2008-4-16
*/
public class ServiceGetWeather {
    private static EndpointReference targetEPR = new EndpointReference(
            "http://www.webxml.com.cn/WebServices/WeatherWebService.asmx");


    public void getResult()throws Exception{
        ServiceClient sender = new ServiceClient();
        sender.setOptions(buildOptions());
        OMElement result = sender.sendReceive(buildParam());
        System.out.println(result);
    }
    private static OMElement buildParam() {
        OMFactory fac = OMAbstractFactory.getOMFactory();
        OMNamespace omNs = fac.createOMNamespace("http://WebXml.com.cn/", "");
        OMElement data = fac.createOMElement("getWeatherbyCityName", omNs);
        OMElement inner = fac.createOMElement("theCityName", omNs);
        inner.setText("长沙");
        data.addChild(inner);
        return data;
    }

    private static Options buildOptions() {
        Options options = new Options();
        options.setSoapVersionURI(SOAP11Constants.SOAP_ENVELOPE_NAMESPACE_URI);
        options.setAction("http://WebXml.com.cn/getWeatherbyCityName");
        options.setTo(targetEPR);
        //options.setProperty(propertyKey, property)
       
        // enabling MTOM in the client side
        // options.setProperty(Constants.Configuration.ENABLE_MTOM, Constants.VALUE_TRUE);
        options.setTransportInProtocol(Constants.TRANSPORT_HTTP);
        return options;
    }
    public static void main(String[] args) throws Exception {
     ServiceGetWeather s = new ServiceGetWeather();
     s.getResult();
    }
}

分享到:
评论

相关推荐

    通过axis使用网上天气预报服务的demo

    这是我在myeclipse中用axis2使用网上提供的天气预报服务的简单demo。你可以在普通的java类中,直接将该代码复制过去即可,当然不要忘了导入axis的jar包。axis的jar包和网上的web service地址,在我的资源和博客中都...

    java 通过axis调用天气预报的webservice

    NULL 博文链接:https://chen106106.iteye.com/blog/1069463

    axis2例子 webservice axis2 示例

    axis2例子 webservice axis2 示例axis2例子 webservice axis2 示例axis2例子 webservice axis2 示例axis2例子 webservice axis2 示例axis2例子 webservice axis2 示例

    axis2相关的jar包

    axis2-adb-1.5.4.jar axis2-adb-codegen-1.5.4.jar axis2-codegen-1.5.4.jar axis2-corba-1.5.4.jar axis2-fastinfoset-1.5.4.jar axis2-java2wsdl-1.5.4.jar axis2-jaxbri-1.5.4.jar axis2-jaxws-1.5.4.jar axis2-...

    完整的axis2 jar包包含实例.zip

    axis2 webservice 服务端jar包: -->axis2-kernel-1.6.1.jar -->axis2-spring-1.6.1.jar -->axis2-transport-http-1.6.1.jar -->XmlSchema-1.4.7.jar -->wsdl4j-1.6.2.jar -->axiom-api-1.2.12.jar -->axiom...

    axis2-1.6.2.zip

    axis2-1.6.2.zip, windows axis2工具,根据 WSDL生成java文件。 1、axis2客户端下载地址:http://mirror.esocc.com/apache//axis/axis2/java/core/1.6.2/axis2-1.6.2-bin.zip; 2、下载解压在D:\Work_Program_...

    axis2-1.7.8.zip

    axis2-1.7.8.zip客户端。2、下载解压在D:\Work_Program_Files目录;在D:\Work_Program_Files\axis2-1.6.2\bin目录有一个wsdl2java.bat文件; 3、设置环境变量,加入AXIS2_HOME=Axis2客户端安装目录,path中追加;%...

    axis2发布webservice和调用axis2服务接口

    本案例实现使用Axis2生成.arr包发布WebService服务,并使用Axis2生成客户端代码方式调用WebService

    axis1.4和axis2相关jar文件

    axis1.4和axis2相关jar文件,axis1.4和axis2相关jar文件

    axis2客户端调用axis1服务接口

    axis2客户端调用axis1服务接口 调用方式 使用RPC方式调用WebService,为了防止冲突可以增加 // 与weblogic的lib冲突配置 System.setProperty("javax.xml.stream.XMLInputFactory", ...

    axis2的API,axis2 API,axis2帮助文档

    axis2的API,axis2 API,axis2帮助文档

    axis2-1.6.1

    axis2-1.6.1

    axis2-idea-plugin-1.7.9.zip_axis2_axis2-idea-plugin_idea导入axis2_

    axis2-idea-plugin-1.7.9

    axis 1.x与axis2.x开发

    axis 1.x与axis2.x开发 以及jar

    axis2相关jar包~eclipse支持插件包

    1、axis2相关jar包如下: axiom-api-1.2.10.jar axiom-dom-1.2.10.jar axiom-impl-1.2.10.jar axis2-adb-1.5.4.jar axis2-adb-codegen-1.5.4.jar axis2-codegen-1.5.4.jar axis2-corba-1.5.4.jar axis2-fastinfoset-...

    axis2 包括源码 文档

    axis2 包括源码 文档

    axis2-1.6.2

    Axis2是下一代 Apache Axis。Axis2 虽然由 Axis 1.x 处理程序模型提供支持,但它具有更强的灵活性并可扩展到新的体系结构。Axis2 基于新的体系结构进行了全新编写,而且没有采用 Axis 1.x 的常用代码。支持开发 Axis...

    axis2c-src-1.6.0

    Apache Axis2/C What is it? ----------- The Apache Axis2/C is a SOAP engine implementation that can be used to provide and consume Web Services. Axis2/C is an effort to implement Axis2 ...

    axis2方式开发webservice

    资源包含了:axis2-1.7.4-bin.zip、axis2-1.7.4-war.zip、axis2-eclipse-codegen-plugin-1.7.4.zip、axis2-eclipse-service-plugin-1.7.4.zip。 myeclipse安装axis2.txt文件:详细说明了myeclipse如何安装axis2插件...

Global site tag (gtag.js) - Google Analytics