首先使用axis2发布WebService
http://www.voidcn.com/article/p-vjopudvo-bqy.html
下载axis2-1.6.2-bin.zip文件并解压到E:\tools\axis2-1.6.2-bin\axis2-1.6.2中,如下图:
然后设置axis2_home环境变量并生成WebService客户端代码,如下图:
其中
D:\Workspaces\java\songjy\axis2-demo\target是生成的WebService客户端代码保存路径
在D:\Workspaces\java\songjy\axis2-demo\target\src\client中则有一个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
异步调用前需生成异步调用客户端代码,执行如下图红色部分命令:
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); } } }
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。