maven版axis2调用cxf服务端开发客户端(三)

一、新建一个maven项目

二、pom.xml引入axis2依赖

<dependency>
    <groupId>org.apache.axis2</groupId>
    <artifactId>axis2</artifactId>
    <version>1.6.2</version>
</dependency>
<dependency>
    <groupId>org.apache.axis2</groupId>
    <artifactId>axis2-adb</artifactId>
    <version>1.6.2</version>
</dependency>
<dependency>
    <groupId>org.apache.axis2</groupId>
    <artifactId>axis2-transport-http</artifactId>
    <version>1.6.2</version>
</dependency>
<dependency>
    <groupId>org.apache.axis2</groupId>
    <artifactId>axis2-transport-local</artifactId>
    <version>1.6.2</version>
</dependency>
<dependency>
    <groupId>org.apache.axis2</groupId>
    <artifactId>axis2-kernel</artifactId>
    <version>1.6.2</version>
</dependency>

三、编写接口调用测试类

public static void main(String[] args) throws Exception {
    //本机tomcat端口默认为8080  
    EndpointReference targetEPR = new EndpointReference("http://localhost:8080/CxfWSServer/webservice/helloWorld");  
    RPCServiceClient sender = new RPCServiceClient();  
    Options options = sender.getOptions();  
    options.setTimeOutInMilliSeconds(2*20000L);//超时时间20s  
    options.setTo(targetEPR);  
  
    QName qname = new QName("http://ws.xie.com/", "sayHi");  
    String str = "April";  
    Object[] param = new Object[]{str};  
    Class<?>[] types = new Class[]{String.class};  //这是针对返值类型的  
    /** 
     * RPCServiceClient类的invokeBlocking方法调用了WebService中的方法。 
     * invokeBlocking方法有三个参数 
     * 第一个参数的类型是QName对象,表示要调用的方法名; 
     * 第二个参数表示要调用的WebService方法的参数值,参数类型为Object[]; 
     * 第三个参数表示WebService方法的返回值类型的Class对象,参数类型为Class[]。 
     *  
     * 当方法没有参数时,invokeBlocking方法的第二个参数值不能是null,而要使用new Object[]{}。 
     */  
    Object[] response = sender.invokeBlocking(qname, param, types);  
    System.out.println(response[0]);  
}

注意:代码中标红的地方分别对应如图所示三个地方

转载于:https://www.cnblogs.com/xiehongwei/p/8082425.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值