axis webservice调用

本文将指导你如何在Java中调用Axis Webservice。首先,你需要导入相应的pom文件,接着封装调用类,最后进行实际的Webservice调用操作。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

1 导入pom文件

<dependency>
            <groupId>org.apache.axis</groupId>
            <artifactId>axis</artifactId>
            <version>1.4</version>
        </dependency>
        <dependency>
            <groupId>commons-discovery</groupId>
            <artifactId>commons-discovery</artifactId>
            <version>0.2</version>
            <exclusions>
                <exclusion>
                    <groupId>commons-logging</groupId>
                    <artifactId>commons-logging</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
        <dependency>
            <groupId>org.apache.axis</groupId>
            <artifactId>axis-jaxrpc</artifactId>
            <version>1.4</version>
        </dependency>
        <dependency>
            <groupId>org.apache.axis</groupId>
            <artifactId>axis-saaj</artifactId>
            <version>1.4</version>
        </dependency>
        <dependency>
            <groupId>wsdl4j</groupId>
            <artifactId>wsdl4j</artifactId>
            <version>1.4</version>
        </dependency>

2 封装调用类

import javax.xml.namespace.QName;
import javax.xml.rpc.ServiceException;

import org.apache.axis.client.Call;
import org.apache.axis.client.Service;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class AxisWebServiceUtils {

    private static Logger  logger  = LoggerFactory.getLogger(AxisWebServiceUtils.class);

    private static Service service = new Service();

    /**
     * 获取调用对象Call
     * @param Url       调用链接
     * @param qName     方法所在类名
     * @param method    调用方法名
     * @return
     */
    public static Call axisSevice(String Url, String qName, String method) {
        Call call = null;
        try {
            call = (Call) service.createCall();
            call.setTargetEndpointAddress(Url);
            call.setOperationName(new QName(qName, method));
        } catch (ServiceException e) {
            logger.error("调用接口出错  url:{}  QName:{} method:{} Exception:{} ", Url, qName, method, e);
            return call;
        }
        return call;
    }
    
}

3 调用

                String result = (String) 
                AxisWebServiceUtils.axisSevice("url",
                        "WebServiceClassName", "WebServiceMethodName")
                        .invoke(new Object[] {param1, list.toArray(),param2,param3});

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值