AXIS2远程调用WebService客户端示例(Eclipse+AXIS2)

环境

版本

Eclipse:Eclipse IDE for Enterprise Java Developers.Version: 2019-03 (4.11.0)
OS: Windows 10, v.10.0, x86_64 / win32
Java version: 1.8.0_211
tomcat:6.0
Axis:axis2-1.6.4
下载地址:https://download.csdn.net/download/qq_32392597/11958674

环境变量配置
  1. 新增系统变量JAVA_HOME,变量值为jdk文件所在位置

在这里插入图片描述
PATH加入:

C:\Program Files\Java\jdk1.8.0_181\lib;
C:\Program Files\Java\jdk1.8.0_181\jre\bin;
%JAVA_HOME%\bin;

Eclipse的菜单栏中,Window --> Preferences --> Web Service --> Axis2

Axis2 runtime location中选择Axis2解压缩包的位置,设置好后,点"OK"即行。
在这里插入图片描述
还有tomcat文件位置在这里插入图片描述
在这里插入图片描述在这里插入图片描述

开发Web Service

新建Web Project
  1. File -> New -> Other… -> Web -> Dynamic Web Project
  2. 将项目名称设置为为WebServiceTest,Target runtime选择之前配置的环境
    在这里插入图片描述
  3. 选择Axis2 Web服务构面,OK后finish在这里插入图片描述
  4. 操作完成后将在工作台中创建一个动态Web项目
    在这里插入图片描述
通过?wsdl地址来生成新创建的服务的客户端
  1. File -> New -> Other… -> Web Services -> Web ServiceClient

  2. 将地址粘贴到service definition中
    在这里插入图片描述

  3. 在configuration中选择之前配置好的server runtime和web service runtime,
    在这里插入图片描述
    client project选择之前新建的WebServiceTest
    在这里插入图片描述

  4. 然后在客户端配置页面,选择Axis2 Client Web Service配置页上的Generate test case to test service复选框。 在这里插入图片描述

  5. 如果选择了该选项,则Axis2发射器将生成与我们提供给客户端的WSDL匹配的JUnit测试用例。这些JUnit测试用例将生成到Axis2WSTestClient项目中名为test的新添加的源目录中。
    在这里插入图片描述

  6. 发现出现中文乱码的问题
    在这里插入图片描述

  7. 在window→preferences→General→workspace→Text file
    encoding设置字符编码为UTF-8即可

在这里插入图片描述
这里有两种方法,一种是按照之前生成的测试代码进行补充数据后调试,还有就是根据AXIS2生成的示例调用其中的方法后调试。我这里先用自己写的代码调用该方法,其实道理都是一样的。
首先展示下代码:
调用代码:

public class Test {

	public static void main(String[] args) {
		try {
		   //实例化PubKey
		  PubKey CValue = new PubKey();
		  PubKeyRequestType Username = new PubKeyRequestType();
		  
		  //设置要传入的参数值
  	  	  Username.setOtherInfo("xx");
  	  	  CValue.setArg0(Username);
  	  	  
  	  	  //实例化BeasPortTypeStub
  	  	  BeasPortTypeStub stub = new BeasPortTypeStub();
  	      PubKeyE c2f = new PubKeyE();
          c2f.setPubKey(CValue);
         
          //调用pubkey方法
          PubKeyResponse2 res = stub.pubKey(c2f);
          
          //获取结果值
          PubKeyResponseType Result = res.localPubKeyResponse.local_return;
  	      String Result2 = Result.getPubKey();
  	      System.out.println(
          		  "PubKeyResult : "+"\n"
          		  +Result2+"\n");    
    } catch (AxisFault e) {
        e.printStackTrace();                  
    } catch (RemoteException e) {
            e.printStackTrace();                  
    }

}

为了更方便了解,这里展示下soapui解析地址后的页面
在这里插入图片描述
运行得到结果,成功:
在这里插入图片描述

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值