首先导入xfire开发webservice的相关jar 在web.xml引入xfire的Servelet web.xml ?xml version="1.0" encoding="UTF-8"?web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemaLoc
首先导入xfire开发webservice的相关jar
在web.xml引入xfire的Servelet
web.xml
<?xml version="1.0" encoding="UTF-8"?> <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5"> <display-name>ws_xfire_server</display-name> <welcome-file-list> <welcome-file>index.html</welcome-file> <welcome-file>index.htm</welcome-file> <welcome-file>index.jsp</welcome-file> <welcome-file>default.html</welcome-file> <welcome-file>default.htm</welcome-file> <welcome-file>default.jsp</welcome-file> </welcome-file-list> <servlet> <servlet-name>XFireServlet</servlet-name> <servlet-class>org.codehaus.xfire.transport.http.XFireConfigurableServlet</servlet-class> <init-param> <param-name>config</param-name> <param-value>../ws/services.xml</param-value> </init-param> <load-on-startup>0</load-on-startup> </servlet> <servlet-mapping> <servlet-name>XFireServlet</servlet-name> <url-pattern>/services/*</url-pattern> </servlet-mapping> </web-app>
注意:
<init-param>
<param-name>config</param-name>
<param-value>../ws/services.xml</param-value>
</init-param>
是修改services.xml文件的默认位置,如果和web.xml在同级目录下设置为: <param-value>services.xml</param-value>,我的设置是:在根目录下的ws目录下(/ws_xfire_server/WebContent/ws/services.xml)。
<init-param>要写在 <load-on-startup>0</load-on-startup>之上,否则编译报错。
services.xml
<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://xfire.codehaus.org/config/1.0"> <service> <name>HelloWS</name> <serviceClass>ws.cf.server.HelloWS</serviceClass> <implementationClass>ws.cf.server.HelloWSImpl</implementationClass> </service> </beans>
接口:
HelloWS.java
package ws.cf.server; public interface HelloWS { String say(String msg); }
HelloWSImpl.java
package ws.cf.server; public class HelloWSImpl implements HelloWS { @Override public String say(String msg) { System.out.println("in server:"+msg); return "hello "+msg; } }
至此 服务端代码已经完成;
http://localhost:8080/ws_xfire_server/services/HelloWS?wsdl
可以查看wsdl文档了。
客户端代码可以使用之前的方式生成,wsimport -keep http://localhost:8080/ws_xfire_server/services/HelloWS?wsdl 生成即可。