axis2 天气预报

<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>

<%@pageimport="org.apache.axiom.om.OMAbstractFactory"%>

<%@pageimport="org.apache.axiom.om.OMElement"%>

<%@pageimport="org.apache.axiom.om.OMFactory"%>

<%@pageimport="org.apache.axiom.om.OMNamespace"%>

<%@pageimport="org.apache.axiom.soap.SOAP11Constants"%>

<%@pageimport="org.apache.axis2.AxisFault"%>

<%@pageimport="org.apache.axis2.Constants"%>

<%@pageimport="org.apache.axis2.addressing.EndpointReference"%>

<%@pageimport="org.apache.axis2.client.Options"%>

<%@ page import="org.apache.axis2.client.ServiceClient"%>

<%!

privatestaticEndpointReferencetargetEPR=newEndpointReference(

            "http://www.webxml.com.cn/WebServices/WeatherWebService.asmx");

    public void getResult() throws Exception {

ServiceClientsender=newServiceClient();

sender.setOptions(buildOptions());

OMElementresult=sender.sendReceive(buildParam());

System.out.println(result);

    }

    private static OMElement buildParam() {

OMFactoryfac=OMAbstractFactory.getOMFactory();

OMNamespaceomNs=fac.createOMNamespace("http://WebXml.com.cn/","");

OMElementdata=fac.createOMElement("getWeatherbyCityName",omNs);

OMElementinner=fac.createOMElement("theCityName",omNs);

inner.setText("成都");

data.addChild(inner);

returndata;

    }

    private static Options buildOptions() {

Optionsoptions=newOptions();

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);

returnoptions;

}

%>

<%

getResult();

%>

相关推荐