1、給web項目添加web service支持,web.xml文件會自動修改。
<SERVLET-NAME>XFireServlet</SERVLET-NAME> <SERVLET-CLASS>org.codehaus.xfire.transport.http.XFireConfigurableServlet</SERVLET-CLASS> <LOAD-ON-STARTUP>0</LOAD-ON-STARTUP> <SERVLET-MAPPING> <SERVLET-NAME>XFireServlet</SERVLET-NAME> <URL-PATTERN>/services/*</URL-PATTERN> </SERVLET-MAPPING>
2、 創建對外提供的服務接口和實現類
接口:HelloService
package com.xaccp.service; public interface HelloService { public String sayHello(String name); }
實現類:HelloServiceImpl
package com.xaccp.service; public class HelloServiceImpl implements HelloService { public String sayHello(String name) { System.out.println("來自客戶端的用戶:" + name); return "服務器說你好:" + name; } }
3、 發布服務