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();
}
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值