`
liuxl1125
  • 浏览: 42002 次
  • 性别: Icon_minigender_1
  • 来自: 南京
社区版块
存档分类
最新评论

axis2 天气预报

阅读更多

<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ page import="org.apache.axiom.om.OMAbstractFactory"%>
<%@ page import="org.apache.axiom.om.OMElement"%>
<%@ page import="org.apache.axiom.om.OMFactory"%>
<%@ page import="org.apache.axiom.om.OMNamespace"%>
<%@ page import="org.apache.axiom.soap.SOAP11Constants"%>
<%@ page import="org.apache.axis2.AxisFault"%>
<%@ page import="org.apache.axis2.Constants"%>
<%@ page import="org.apache.axis2.addressing.EndpointReference"%>
<%@ page import="org.apache.axis2.client.Options"%>
<%@ page import="org.apache.axis2.client.ServiceClient"%>

<%!
 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 如果不是通过代理上网,此句可省
        // options.setProperty(HTTPConstants.PROXY, buildProxy());
        options.setTransportInProtocol(Constants.TRANSPORT_HTTP);
        return options;
    }
 %>
 
 <%
          getResult();
  %>

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics