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