加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

使用axis2生成客户端(异步/同步)调用代码

发布时间:2020-12-17 00:11:17 所属栏目:安全 来源:网络整理
导读:首先使用axis2发布WebService http://www.voidcn.com/article/p-vjopudvo-bqy.html ? 下载axis2-1.6.2-bin.zip文件并解压到E:toolsaxis2-1.6.2-binaxis2-1.6.2中,如下图: 然后设置axis2_home环境变量并生成WebService客户端代码,如下图: 其中 D:Work

首先使用axis2发布WebService

http://www.voidcn.com/article/p-vjopudvo-bqy.html

?

下载axis2-1.6.2-bin.zip文件并解压到E:toolsaxis2-1.6.2-binaxis2-1.6.2中,如下图:

然后设置axis2_home环境变量并生成WebService客户端代码,如下图:

其中

D:Workspacesjavasongjyaxis2-demotarget是生成的WebService客户端代码保存路径

在D:Workspacesjavasongjyaxis2-demotargetsrcclient中则有一个java文件HelloStub.java

同步调用示例代码

public void test(){
		try {
			HelloStub.Hello hello = new HelloStub.Hello();
			hello.setName("猪八戒");
			HelloStub stub = new HelloStub();
			System.out.println(stub.hello(hello).local_return);
		} catch (AxisFault e) {
			e.printStackTrace();
		} catch (RemoteException e) {
			e.printStackTrace();
		}
		
	}


执行效果如下:

您好,猪八戒,现在的时间是:Mon Aug 05 11:01:08 CST 2013

?

异步调用前需生成异步调用客户端代码,执行如下图红色部分命令:

相比之下,在生成异步客户端代码时多了个参数:-a

异步调用示例代码:

public class Test extends TestCase {

	public void test(){
		try {
			HelloStub stub = new HelloStub();
			HelloStub.Hello hello = new HelloStub.Hello();
			hello.setName("沙和尚");
			System.out.println(stub.hello(hello).local_return);//同步
			hello.setName("孙行者");
			stub.starthello(hello,new AsynCallback());//异步
			Thread.sleep(1000);
		} catch (AxisFault e) {
			e.printStackTrace();
		} catch (RemoteException e) {
			e.printStackTrace();
		} catch (InterruptedException e) {
			e.printStackTrace();
		}
	}
	
	private class AsynCallback extends HelloCallbackHandler {

		@Override
		public void receiveResulthello(HelloResponse result) {
			
			System.out.println(result.local_return);
			
		}

	}
	
}

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读