1.在eclipse中创建web项目
2.再把jar包COPY到lib目录下
3.在web.xml中加入以下代码:
org.apache.axis.transport.http.AxisHTTPSessionListener
AxisServlet
Apache-Axis Servlet
org.apache.axis.transport.http.AxisServlet
AdminServlet
Axis Admin Servlet
org.apache.axis.transport.http.AdminServlet
100
SOAPMonitorService
SOAPMonitorService
org.apache.axis.monitor.SOAPMonitorService
SOAPMonitorPort
5001
100
AxisServlet
/services/*
SOAPMonitorService
/SOAPMonitor
4.创建服务端类
package server;
public class SayHello {
public String getName(String name)
{
return "hello "+name;
}
}
5.编写WebRoot\WEB-INF\deploy.wsdd文件
6.在tomcat中启动项目
7.
打开cmd 进入 目录 :WEB-INF\
输入部署命令(注意更改命令中服务的地址和端口)
java -Djava.ext.dirs=lib org.apache.axis.client.AdminClient -lhttp://localhost:8080/axis/services deploy.wsdd
若显示
Processing file deploy.wsdd
Done processing
则表示发布服务成功
And now... Some Services
AdminService (wsdl)
AdminService
Version (wsdl)
getVersion
SayHello (wsdl)
getName
点击 SayHello (wsdl) 便会显示其XML ,点右健,查看源文件,保存XML为WebRoot\WEB-INF\SayHello.xml
9.创建客户端
编写axitDemo\WebRoot\WEB-INF\make.bat文件 内容如下
java -cp ".;lib\axis-ant.jar;lib\axis.jar;lib\commons-discovery-0.2.jar;lib\commons-logging-1.0.4.jar;lib\jaxrpc.jar;lib\log4j-1.2.8.jar;lib\log4j.properties;lib\saaj.jar;lib\wsdl4j-1.5.1.jar" org.apache.axis.wsdl.WSDL2Java -p %1 %2
10. 打开cmd进入WEB-INF目录
执行命令: make com.webserivce SayHello.xml
成功后会在WEB-INF目录下生成
com.webserivce 包下面会有java类 如下图:
COPY com.webserivce包到SRC目录下
12.编写客户端测试Client 类
package client;
import java.rmi.RemoteException;
import com.webserivce.SayHelloServiceLocator;
import com.webserivce.SayHello_PortType;
public class Client {
private SayHello_PortType dataService;
public Client()throws Exception{
SayHelloServiceLocator service= new SayHelloServiceLocator();
this.setDataService(service.getSayHello());
}
private String getName(String name) throws RemoteException{
return dataService.getName(name);
}
public static void main(String[] args)throws Exception {
Client c = new Client();
String a = c.getName("Test axis!");
System.out.println(a);
}
public SayHello_PortType getDataService() {
return dataService;
}
public void setDataService(SayHello_PortType dataService) {
this.dataService = dataService;
}
}
运行Client 类
hello Test axis!
整个过程就完成啦。。。。。
posted on 2011-05-25 11:53 梓枫 阅读(704) 评论(0) 编辑 收藏 所属分类: webservice