webservice调用接口随记(axis)

使用的工具包是org.apache.axis1.4  ,需要的maven包如下:

        <!-- https://mvnrepository.com/artifact/org.apache.axis/axis -->
        <dependency>
            <groupId>org.apache.axis</groupId>
            <artifactId>axis</artifactId>
            <version>1.4</version>
        </dependency>

        <!-- https://mvnrepository.com/artifact/axis/axis-jaxrpc -->
        <dependency>
            <groupId>axis</groupId>
            <artifactId>axis-jaxrpc</artifactId>
            <version>1.4</version>
        </dependency>
        <!--&lt;!&ndash; https://mvnrepository.com/artifact/commons-discovery/commons-discovery &ndash;&gt;-->
        <dependency>
            <groupId>commons-discovery</groupId>
            <artifactId>commons-discovery</artifactId>
            <version>0.4</version>
        </dependency>

        <dependency>
            <groupId>wsdl4j</groupId>
            <artifactId>wsdl4j</artifactId>
            <version>1.6.2</version>
        </dependency>

最后附上整体代码


import org.apache.axis.client.Call;
import org.apache.axis.client.Service;

import javax.xml.namespace.QName;

public class WebServiceTest {

    public static void main(String[] args) {

        String endPoint = "http://xxx/Service";// webservice地址
        String targetNamespace = "http://localhost:88/xxx/services";// 命名空间
        String methodName = "test";// 握手验证接口
        try {
            Service service = new Service();
            Call call = (Call) service.createCall();
            call.setTargetEndpointAddress(endPoint);
            call.setOperation(methodName);// 调用的方法
            call.setOperationName(new QName(targetNamespace, methodName));
            Object[] arr = new Object[2];//所需参数数组  参数个数需要与方法对应
            arr[0] = "11";//第一个参数
            arr[1] = "22";//第二个参数
            Object str = call.invoke(arr); // 调用方法
            System.out.println(str); // 返回
        } catch (Exception ex) {
            ex.printStackTrace();
        }
    }

}

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值