axis 发布的一个小例子 .
1 创建web工程AxisTest,加入axis-1_4的lib以下jar包;
2 web.xml 设置
<?xml version="1.0" encoding="ISO-8859-1"?> <!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN" "http://java.sun.com/dtd/web-app_2_3.dtd"> <web-app> <display-name>Apache-Axis</display-name> <listener> <listener-class>org.apache.axis.transport.http.AxisHTTPSessionListener</listener-class> </listener> <servlet> <servlet-name>AxisServlet</servlet-name> <display-name>Apache-Axis Servlet</display-name> <servlet-class> org.apache.axis.transport.http.AxisServlet </servlet-class> </servlet> <servlet> <servlet-name>AdminServlet</servlet-name> <display-name>Axis Admin Servlet</display-name> <servlet-class> org.apache.axis.transport.http.AdminServlet </servlet-class> <load-on-startup>100</load-on-startup> </servlet> <servlet> <servlet-name>SOAPMonitorService</servlet-name> <display-name>SOAPMonitorService</display-name> <servlet-class> org.apache.axis.monitor.SOAPMonitorService </servlet-class> <init-param> <param-name>SOAPMonitorPort</param-name> <param-value>5001</param-value> </init-param> <load-on-startup>100</load-on-startup> </servlet> <servlet-mapping> <servlet-name>AxisServlet</servlet-name> <url-pattern>/servlet/AxisServlet</url-pattern> </servlet-mapping> <servlet-mapping> <servlet-name>AxisServlet</servlet-name> <url-pattern>*.jws</url-pattern> </servlet-mapping> <servlet-mapping> <servlet-name>AxisServlet</servlet-name> <url-pattern>/services/*</url-pattern> </servlet-mapping> <servlet-mapping> <servlet-name>SOAPMonitorService</servlet-name> <url-pattern>/SOAPMonitor</url-pattern> </servlet-mapping> <!-- uncomment this if you want the admin servlet --> <!-- <servlet-mapping> <servlet-name>AdminServlet</servlet-name> <url-pattern>/servlet/AdminServlet</url-pattern> </servlet-mapping> --> <session-config> <!-- Default to 5 minute session timeouts --> <session-timeout>5</session-timeout> </session-config> <!-- currently the W3C havent settled on a media type for WSDL; http://www.w3.org/TR/2003/WD-wsdl12-20030303/#ietf-draft for now we go with the basic 'it's XML' response --> <mime-mapping> <extension>wsdl</extension> <mime-type>text/xml</mime-type> </mime-mapping> <mime-mapping> <extension>xsd</extension> <mime-type>text/xml</mime-type> </mime-mapping> <welcome-file-list id="WelcomeFileList"> <welcome-file>index.jsp</welcome-file> <welcome-file>index.html</welcome-file> <welcome-file>index.jws</welcome-file> </welcome-file-list> </web-app> |
3 开发服务器端java业务类
package com.axis.test ; public class HelloWSDD {
public int count=0;
public String hello(String name){
count++; System.out.println(count); System.out.println(name); return "hello---"+name; } public float add(float a,float b){
System.out.println(count); System.out.println(a+b); return a+b; } } |
4 发布方法--在WEB-INF下创建 deploy.wsdd
<deployment xmlns="http://xml.apache.org/axis/wsdd/" xmlns:java="http://xml.apache.org/axis/wsdd/providers/java">
<service name="HelloWSDD" provider="java:RPC"> <parameter name="className" value="com.axis.test.HelloWSDD"/> <parameter name="allowedMethods" value="*"/> <parameter name="scope" value="request"/> </service> </deployment> |
5 在E:\webservice下新建deployToWsdl.bat 发布,生产wsdl服务地址
(http://localhost:8080/AxisTest/services/HelloWSDD?wsdl)
@echo off set Axis_Lib=E:\webservice\axis-1_4\lib set Java_Cmd=java -Djava.ext.dirs=%Axis_Lib% set Axis_Servlet=http://localhost:8080/AxisTest/servlet/AxisServlet %Java_Cmd% org.apache.axis.client.AdminClient -l%Axis_Servlet% deploy.wsdd echo 完成! echo. & pause |
执行此文件,启动tomcat,访问http://localhost:8080/AxisTest/servlet/AxisServlet,即可看到已经发布成功
6在E:\webservice下新建根据wsdd生产客户端代码 wsdlToClient.bat
@echo off set Axis_Lib=E:\webservice\axis-1_4\lib set Java_Cmd=java -Djava.ext.dirs=%Axis_Lib% set Output_Path=E:\webservice\client set Package=com.ws.testService %Java_Cmd% org.apache.axis.wsdl.WSDL2Java -o%Output_Path% -p%Package% http://localhost:8080/AxisTest/services/HelloWSDD?wsdl echo 完成! echo. & pause |
执行后,会在当前目录生成client文件夹,将里面的com文件夹拷贝到工程的src下
7 客户端测试
package com.test; import java.rmi.RemoteException; import com.ws.testService.HelloWSDDService; import com.ws.testService.HelloWSDDServiceLocator; import com.ws.testService.HelloWSDD_PortType; public class Test { public static void main(String[] args) throws RemoteException, Exception { HelloWSDDService service = new HelloWSDDServiceLocator(); HelloWSDD_PortType client = service.getHelloWSDD(); String value = client.hello("hello,你好"); System.out.println(value); } } |