1)首先要定义一个服务的接口
在这里写个简单模拟火车对外提供的 查询,订票,取消预订的服务。
package com.huas.webservice;
public interface TrainService
{
public String lookup(String info);
public String reservation(String info);
public String cancel(String name);
}
2)实现接口
package com.huas.webservice.impl;
import com.huas.webservice.TrainService;
public class TrainServiceImpl implements TrainService
{
public String cancel(String name)
{
// add you own service logic
return name;
}
public String lookup(String info)
{
// TODO add you own service logic
return info;
}
public String reservation(String info)
{
// TODO add you own service logic
return info;
}
}
3)配置XFire的环境
1:在src下面建立下面的文件结构 META-INF->xfire->services.xml
service.xml的文件的内容如下:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://xfire.codehaus.org/config/1.0">
<service>
<!--you service name-->
<name>TrainService</name>
<!--you service interface name-->
<serviceClass>com.huas.webservice.TrainService</serviceClass>
<!--you service implementation class name-->
<implementationClass>com.huas.webservice.impl.TrainServiceImpl</implementationClass>
</service>
</beans>
2:在web.xml文件中配置
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="2.5" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
<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>/*</url-pattern>
</servlet-mapping>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
</web-app>
上面的工作都做完后,就可以吧这个项目部署到Tomcat上运行了。
在浏览器地址栏敲入:http://localhost:8080/TravelAgent/TravelService。
如果上面的都配置成功了就可以看到一个WSDL文件。
Xfire的JAR包读者可以自己去Apache的官网下载。[size=medium][/size]
java 利用Xfire 来生成Webservice 的WSDL文件
猜你喜欢
转载自chen106106.iteye.com/blog/1069478
今日推荐
周排行