1. 在这个地址http://ws.apache.org/axis/下载最新的axis包axis-bin-1_4.zip
2. 解压axis-bin-1_4.zip,将/axis-1_4/webapps目录下的axis文件夹拷贝到web容器下(如tomcat的webapps工程目录下)
3. 启动tomcat,打开http://localhost:8080/axis/happyaxis.jsp链接 查看 Needed Components 下的包是否有找不到的,有就要下载相应的包放到lib文件夹下
4. 以上工作是环境的搭建,下面测试一个简单helloworld的例子
5. 写一个测试类
?public class HelloWorld
?{
???? public String helloWorld()
???? {
??return "HelloWorld";
???? }
?}
?将上面程序保存为名称为HelloWorld.jws的文件,放到apache-tomcat-6.0.30/webapps/axis的目录下
6. 用http://localhost:8080/axis/HelloWorld.jws链接打开浏览器可看到
?There is a Web Service here
?Click to see the WSDL
?说明发布成功
?
7. 写个本地的测试类测试
??????? import org.apache.axis.client.Call;
?import org.apache.axis.client.Service;
?public class WebServiceClient
?{
???? public static void main(String args[])
???? {
??System.out.println("开始调用WebService ");
??try
??{
????? //WebService所在的url?
????? String endpoint = "http://localhost:8080/axis/HelloWorld.jws";
????? //创建Serivce对象,Service对用用于创建Call对象?
????? Service service = new Service();
????? //创建Call对象,Call对象用于调用服务?
????? Call call = (Call)service.createCall();
????? // 为Call对象设置WebService的url??
????? call.setTargetEndpointAddress(new java.net.URL(endpoint));
????? //为Call对象设置调用的方法名?
????? call.setOperationName("HelloWorld");
????? //调用WebService的方法,并获得返回值?
????? String s = (String)call.invoke(new Object[] {});
????? //输出返回值?
????? System.out.println(s);
??}
??catch (Exception e)
??{
????? System.out.println(e.toString());
??}
??System.out.println("调用WebService正常结束 ");
???? }
?}
?需要相应的jar有axis.jar、commons-discovery-0.2.jar、commons-logging-1.0.4.jar、xerces.jar
测试结果
?开始调用WebService
?HelloWorld
?调用WebService正常结束
测试环境:tomcat6+axis2
测试总结:整个简单的axis搭建和以jws方式发布webservice的开发测试就是这样的