webservice xfire编写webService接口
1、下载
a.下载xfire(下载地址)
2、部署
a.解压xfire,将lib目录下所有的jar添加到web-inf/lib目录下
下面是我的工程:
b、编写web.xml目录
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
<?xml version="1.0" encoding="UTF-8"?> <web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"> <display-name></display-name> <servlet> <servlet-name>XFireServlet</servlet-name> <servlet-class> org.codehaus.xfire.transport.http.XFireConfigurableServlet </servlet-class> </servlet> <servlet-mapping> <servlet-name>XFireServlet</servlet-name> <url-pattern>/servlet/XFireServlet/*</url-pattern> </servlet-mapping> <servlet-mapping> <servlet-name>XFireServlet</servlet-name> <url-pattern>/services/*</url-pattern> </servlet-mapping> </web-app>
c、编写接口文件
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
package org.study.webservice.inf; import java.util.List; public interface IWebService { public List<String> searchString(String key); public String sayHello(String name); }
d、编写具体的实现类
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
package org.study.webservice.impl; import java.util.ArrayList; import java.util.List; import org.study.webservice.inf.IWebService; public class WebServiceImpl implements IWebService { public List<String> searchString(String key) { List<String> arrayList = new ArrayList<String>(); arrayList.add("aa"); arrayList.add("bb"); arrayList.add("cc"); return arrayList; } public String sayHello(String name) { return name + ",你好,this is my first webservice xfire demo."; } }
e、在WebRoot/META-INF目录下新建xfire文件夹,并在xfire文件夹下新建services.xml文件,内容如下:
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://xfire.codehaus.org/config/1.0"> <service> <name>xfireService</name> <namespace>http://localhost:10086/webServiceDemo/xfireService</namespace> <serviceClass>org.study.webservice.inf.IWebService</serviceClass> <implementationClass>org.study.webservice.impl.WebServiceImpl</implementationClass> </service> </beans>
f、将工程部署到tomcat目录下,并将META-INF复制一份到WEB-INF/classes目录下
到现在为止,整个webservice已部署成功,启动tomcat服务,访问http://localhost:10086/webServiceDemo/services