码迷,mamicode.com
首页 > 其他好文 > 详细

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

时间:2017-12-21 21:46:15      阅读:250      评论:0      收藏:0      [点我收藏+]

标签:rpc   span   dep   name   system   cat   org   ebs   注意   

一、新建一个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]);  
}

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

技术分享图片

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

标签:rpc   span   dep   name   system   cat   org   ebs   注意   

原文地址:http://www.cnblogs.com/xiehongwei/p/8082425.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!