1、下载所需要的ja包来搭建环境:
需要的jar包有org.apache.axis2.eclipse.service.plugin_1.6.2.jar、org.apache.axis2.eclipse.codegen.plugin_1.6.2.jar、axis2-1.6.2-bin.zip、axis2-1.6.2-war.zip
将前两个jar包解压放到C:\Program Files\Genuitec\MyEclipse 8.5\dropins中,重新打开myeclipse8.5,file---new----other下出现axis2 wizard2 环境搭建成功;
2、将axis2-1.6.2-war.zip解压,将axis2.war部署到tomcat的webapp文件夹中,启动tomcat,这时会在webapp出现axis2文件夹;
3、开发webservice 服务端:
创建一web项目:SayHello,
在com包下创建一个类:Hello.java;
public class Hello {
public String helloWorld(String name){
return "helloworld "+ name;
}
}
4、创建wsdl文件:
file--new---other---axis2 code generator---->next 选中generator a wsdl form a java source file,
在Fully qualified class name 中填写类的名称(包含包的名称如com.Hello),点击add folder添加classes路径即
SayHello项目下的web-info下的classes文件夹这个路径;然后点击next ,为.wsdl文件创建一个名称,点击next
到此为止wsdl文件创建完成;
5、根据wsdl文件创建一个:
file---new---other----axis2 service archiver----next 在工作目录中找到SayHello项目的classes文件,点next
然后选择select wsdl 选择上面创建的wsdl文件,并将要生成的arr文件的存放路径指定为WEB-INF下;
到此为止webservice创建完成,将创建的aar文件放到tomcat的webapps\axis2\WEB-INF\services中重启tomcat这是发布的服务的访问就可以被访问;
6、创建一个调用webservice 服务中的方法:
public class Client {
public static void main(String[] args) throws Exception{
// 使用RPC方式调用WebService
RPCServiceClient serviceClient = new RPCServiceClient();
Options options = serviceClient.getOptions();
// 指定调用WebService的URL
EndpointReference targetEPR = new
EndpointReference("http://localhost/axis2/services/service");
// 指定method方法的参数值
String name="lid";
Object[] opAddEntryArgs = new Object[] {name};
// 指定method方法返回值的数据类型的Class对象
Class[] classes = new Class[] {String.class};
// 指定要调用的method方法及WSDL文件的命名空间
QName opAddEntry = new QName("http://ws.apache.org/axis2", "helloWorld");
// 调用method方法并输出该方法的返回值
System.out.println(serviceClient.invokeBlocking(opAddEntry, opAddEntryArgs, classes));
}
}
到此为止环境的搭建 以及一个小demo完成;