接口:
package cicro;
public interface Isayhello
{
public String example(String message);
}
实现类:
package cicro;
public class sayhelloImpl implements Isayhello
{
public String example(String message)
{
return message;
}
}
web.xml文件的配置:
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="2.4" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
<servlet>
<servlet-name>XFireServlet</servlet-name>
<servlet-class>org.codehaus.xfire.transport.http.XFireConfigurableServlet</servlet-class>
<load-on-startup>0</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>XFireServlet</servlet-name>
<url-pattern>/services/*</url-pattern>
</servlet-mapping>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
</web-app>
services.xml文件的配置;
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://xfire.codehaus.org/config/1.0">
<service>
<name>sayhello</name>
<serviceClass>cicro.Isayhello</serviceClass>
<implementationClass>cicro.sayhelloImpl</implementationClass>
<style>wrapped</style>
<use>literal</use>
<scope>application</scope>
</service></beans>
整个工程目录如下:
在tomcat/webapp目录下创建一个名为webservice的目录;目录结构如下:
webservice
|
|------WEB-INF
|
|-----classes
| |
| |----META-INF
| |
| |-----xfire
| |
| |----services.xml
|-----lib
|
------web.xml
就要把此java文件编译后的class文件放在calsses目录下
把xfire所需要的jar放在lib目录下
启动tomcat 在浏览器地址栏中输入:
http://localhost:8080/webservice/services/
如果能够显示 xml文档那么我们的一个webservice服务就算发布成功了;
以上例子是本人亲自运行成功过!接下来有时间的话会贴出webservice的高级应用