您的位置:首页 > 编程语言 > Java开发

java axis2 调用webservice接口客户端

2017-09-26 00:00 429 查看
摘要: jar包版本axis2-1.7.6
代码可以直接运行。
jar包已经精简到最小了。不用引用那么多没用的jar包

package com.quickmap.common;

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.axis2.AxisFault;
import org.apache.axis2.addressing.EndpointReference;
import org.apache.axis2.client.Options;
import org.apache.axis2.client.ServiceClient;

/**
* Created by matt0614@qq.com on 2017/6/6 0006.
*/
public class WebServicesClient {
public static void main(String[] args) throws Exception {
getRes3();
}

public static void getRes3(){
try {
String soapBindingAddress = "http://www.webxml.com.cn/WebServices/ChinaZipSearchWebService.asmx";
ServiceClient sender = new ServiceClient();
EndpointReference endpointReference = new EndpointReference(
soapBindingAddress);
Options options = new Options();
options.setAction("http://WebXml.com.cn/getSupportCity");
options.setTo(endpointReference);
//options.setProperty(HTTPConstants.CHUNKED, "false");
sender.setOptions(options);
OMFactory fac = OMAbstractFactory.getOMFactory();
// 这个和qname差不多,设置命名空间
OMNamespace omNs = fac.createOMNamespace("http://WebXml.com.cn/",
"getSupportCity");
OMElement data = fac.createOMElement("getSupportCity", omNs);
// 对应参数的节点
String[] strs = new String[] {"byProvinceName" };
// 参数值
String[] val = new String[] {"上海"};
for (int i = 0; i < strs.length; i++) {
OMElement inner = fac.createOMElement(strs[i], omNs);
inner.setText(val[i]);
data.addChild(inner);
}
// 发送数据,返回结果
OMElement result = sender.sendReceive(data);
System.out.println(result.toString());
} catch (AxisFault ex) {
ex.printStackTrace();
}

}

}

引用最精简jar包列表:



jar包列表下载地址:
http://download.csdn.net/download/matt0614/9995548
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  java webservice axis2