发布简单的webService
?
public class SimpleService{ public String getName(String name) { return "你好 " + name; } public int getAge(){ return (int)(Math.random()*100); } }
http://localhost:8080/axis2/services/listServices
?
每发布一个webService程序,就会相应的产生一个对应的wsdl文件:
使用axis2自带的命令 wsdl2java 根据wsdl文件自动生成调用webService的代码:
%AXIS2_HOME%\bin\wsdl2java-uri
-url参数指定了wsdl文件的路径,可以是本地路径,也可以是网络路径
-p参数指定了生成的Java类的包名
-o参数指定了生成的一系列文件保存的根目录
执行完命令后,在当前目录下生成了一个client目录,在client/src/etoak目录下找到一个文件:SimpleServiceStub.java。这个文件负责调用webService。
5、使用客户端程序
public class StubClient {public static void main(String[] args)throws Exception {SimpleServiceStub stub = new SimpleServiceStub();SimpleServiceStub.GetName getName = new SimpleServiceStub.GetName();getName.setArgs0("charles");System.out.println(stub.getName(getName).get_return());System.out.println(stub.getAge().get_return());}}?
?