java axis2 调用webservice接口客户端

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包列表:

111323_AQxd_2328605.png

jar包列表下载地址:

http://download.csdn.net/download/matt0614/9995548

转载于:https://my.oschina.net/matt0614/blog/1543476

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值