微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

Axis2 start guide

@H_404_1@
下载:http://ws.apache.org/axis2/最新版本 axis2-1.6.3-war.zip axis2   |--axis-web  [axis的管理页面]   |--WEB-INF      |--conf/  [配置文件:axis2.xml]      |--services         |--services.list [文本文件] |--*.aar         [其实是jar格式]   |--package/*.class   |--meta-inf/service.xml      |--modules 验证:http://localhost:8080/axis2/services/listServices       http://localhost:8080/axis2/axis2-admin/ 服务端 (1)用POJO形式发布(无需配置)    只需要将没有包名的class文件拷到 /WEB-INF/pojo/ 下面(如果不存在请新建目录)即可。    http://localhost:8080/axis2/services/HelloService/sayHello    http://localhost:8080/axis2/services/HelloService/sayHelloToPerson?name=bill       <ns:sayHelloToResponse xmlns:ns="http://ws.apache.org/axis2"> <return>hello,bill</return>       </ns:sayHelloToResponse>    注:axis2支持热部署,所以无需重启tomcat。(<parameter name="hotdeployment">true</parameter>)        也可以自定义pojo目录名称:<deployer class="org.apache.axis2.deployment.POJODeployer" directory="pojo" extension=".class"/> (2)使用services.xml配置文件发布    将class文件和/MATA/INF打包成 .aar放到/WEB-INF/services目录下即可。 <?xml version="1.0" encoding="UTF-8"?> <service name="HelloService2">     <description>         Web Service例子      </description>     <parameter name="ServiceClass">         services.axis2.HelloService2     </parameter>     <operation name="sayHello">         <messageReceiver class="org.apache.axis2.rpc.receivers.RPcmessageReceiver" />     </operation>     <operation name="sayHelloTo"> <!--返回值为void-->         <messageReceiver class="org.apache.axis2.rpc.receivers.RPCInOnlyMessageReceiver" />     </operation> </service> 客户端 (1)API调用     //指定调用WebService的URL     RPCServiceClient serviceClient = new RPCServiceClient();     Options options = serviceClient.getoptions();     EndpointReference target = new EndpointReference(               "http://localhost:8080/axis2/services/HelloService");       options.setTo(target);     //指定调用方法及WSDL文件的命名空间       QName qname = new QName("http://ws.apache.org/axis2","sayHelloTo");     //参数值,无参数使用空数组     Object[] args = new Object[] {"美女"};     //返回值的数据类型     Class[] returnTypes = new Class[] {String.class};          System.out.println(serviceClient.invokeBlocking(qname,args,returnTypes)[0]);     //如果没有返回值,调用invokeRobust方法:serviceClient.invokeRobust(qname,args); (2)用wsdl2java命令生成客户端代码     wsdl2java -uri http://localhost:8080/axis2/services/HelloService?wsdl -s -o stub -p client     // -o 输出路径,-p 表示package,  当前目录:/stub/src/client/HelloService*         HelloServiceStub stub = new HelloServiceStub();         HelloServiceStub.SayHelloTo gg = new HelloServiceStub.SayHelloTo();         gg.setName("美女");         System.out.println( stub.sayHello().get_return());         System.out.println(stub.sayHelloTo(gg).get_return()); 

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。

相关推荐