一、axis环境搭建
1.安装环境 JDK、Tomcat或Resin、eclipse等.
2.到 http://www.apache.org/dyn/closer.cgi/ws/axis/1_4下载Axis的jar包
3.将Axis的jar包放入WEB-INF/lib目录下
二、编写web service服务端
1.编写服务
package com.webservice; public class HelloWebservice { public String doService(String name) { String result = "Hello " + name; return result; } }
2.配置web.xml文件
<!--start of webservice setting --> <servlet> <servlet-name>axis</servlet-name> <servlet-class>org.apache.axis.transport.http.AxisServlet</servlet-class> <load-on-startup>5</load-on-startup> </servlet> <servlet-mapping> <servlet-name>axis</servlet-name> <url-pattern>/webservice/*</url-pattern> </servlet-mapping> <servlet> <servlet-name>SOAPMonitorService</servlet-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>SOAPMonitorService</servlet-name> <url-pattern>/SOAPMonitor</url-pattern> </servlet-mapping> <!-- end of webservice setting -->
3.配置WEB-INF/server-config.wsdd文件
<?xml version="1.0" encoding="UTF-8"?> <deployment name="defaultClientConfig" xmlns:java="http://xml.apache.org/axis/wsdd/providers/java" xmlns:handler="http://xml.apache.org/axis/wsdd/providers/handler" xmlns="http://xml.apache.org/axis/wsdd/"> <globalConfiguration name="defaultClientConfig"> <requestFlow name="RequestFlow1" type=""> <handler name="Handler1" type="java:org.apache.axis.handlers.JWSHandler"> <parameter name="scope" value="session" /> </handler> <handler name="Handler2" type="java:org.apache.axis.handlers.JWSHandler"> <parameter name="scope" value="request" /> <parameter name="extension" value=".jwr" /> </handler> </requestFlow> </globalConfiguration> <handler name="URLMapper" type="java:org.apache.axis.handlers.http.URLMapper" /> <handler name="LocalResponder" type="java:org.apache.axis.transport.local.LocalResponder" /> <handler name="Authenticate" type="java:org.apache.axis.handlers.SimpleAuthenticationHandler" /> <transport name="http" type=""> <requestFlow name="RequestFlow1" type=""> <handler name="Handler1" type="URLMapper" /> <handler name="Handler2" type="java:org.apache.axis.handlers.http.HTTPAuthHandler" /> </requestFlow> </transport> <transport name="local" type=""> <responseFlow name="ResponseFlow1" type=""> <handler name="Handler1" type="LocalResponder" /> </responseFlow> </transport> <!-- 每个webservice均需要一个如下配置,name为访问时的请求名 --> <service name="helloService" provider="java:RPC" style="rpc" use="encoded"> <parameter name="scope" value="Request"/> <!-- className为实际访问的服务类 --> <parameter name="className" value="com.webservice.HelloWebservice"/> <!-- allowedMethods为实际访问的服务方法 --> <parameter name="allowedMethods" value="doService" /> </service> </deployment>
4.访问webservice
地址栏输入:http://localhost:8080/项目名/webservice/helloService?wsdl
出现如图所示生成wsdl文件即说明服务端搭建成功
5.使用soapUI测试接口
返回成功,服务端搭建完成。
时间: 2024-10-07 13:24:58