Eclipse使用Xfire开发WebService

一、开发工具:Java EE -Eclipse ,xfire1.2.6,tomcat6.0.33

二,开发步骤

         1、在eclipse下新建dynamic Web Project,比如起名为InventoryServer.

 选择target runtime ,Apache Tomcat v6.0,也可以在以后创建server关联InventoryServer

     2、导入库,将xfire1.2.6目录下的xfire-all-1.2.6.jar文件,以及xfire-1.2.6\lib目录下的所有文件拷贝到InventoryServer工程的

WebContent\WEB-INF\lib目录下。
     3、修改WebContent\WEB-INF\web.xml配置文件的内容,下面是修改后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" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
 xsi:schemaLocation="
http://java.sun.com/xml/ns/javaeehttp://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
 id="WebApp_ID" version="2.5">
 <display-name>InventoryServer</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>
 </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>

       4、编写需要发布为WebService的Java类。

public interface Inventory {
 
  public int UpLoadData(List<AssetBean> list);
 
  public List<AssetBean> DownLoadData();
}

    在写一个类来实现上面的接口:

public class InventoryImpl implements Inventory{

 @Override
 public List<AssetBean> DownLoadData() {
  // TODO Auto-generated method stub
  AssetsDao asd=new AssetsDao();
  return asd.findAll();
 }

 @Override
 public int UpLoadData(List<AssetBean> list) {
  // TODO Auto-generated method stub

      AssetsDao asd=new AssetsDao();
     int res=asd.insertMsgList(list);
     if(res==asd.SUCCESS) return 1;
     return -1;     

    }
}

AssetBean类如下:

public class AssetBean{
 private String code=null;
 private String name=null;
 private String department=null;
 private String vesting_people=null;
 private Date purchasetime=null;
 private int netvalue=0;
 private String classification=null;
 private String property_unit=null;
 private Date now=null;
 
 public AssetBean() {
  super();
  // TODO Auto-generated constructor stub
 }
 public AssetBean(String code, String name, String department,
   String vestingPeople, Date purchasetime, int netvalue,
   String classification, String propertyUnit) {
  super();
  this.code = code;
  this.name = name;
  this.department = department;
  vesting_people = vestingPeople;
  this.purchasetime = purchasetime;
  this.netvalue = netvalue;
  this.classification = classification;
  property_unit = propertyUnit;
 }
 public String getCode() {
  return code;
 }
 public void setCode(String code) {
  this.code = code;
 }
 public String getName() {
  return name;
 }
 public void setName(String name) {
  this.name = name;
 }
 public String getDepartment() {
  return department;
 }
 public void setDepartment(String department) {
  this.department = department;
 }
 public String getVesting_people() {
  return vesting_people;
 }
 public void setVesting_people(String vestingPeople) {
  vesting_people = vestingPeople;
 }
 public Date getPurchasetime() {
  return purchasetime;
 }
 public void setPurchasetime(Date purchasetime) {
  this.purchasetime = purchasetime;
 }
 public int getNetvalue() {
  return netvalue;
 }
 public void setNetvalue(int netvalue) {
  this.netvalue = netvalue;
 }
 public String getClassification() {
  return classification;
 }
 public void setClassification(String classification) {
  this.classification = classification;
 }
 public String getProperty_unit() {
  return property_unit;
 }
 public void setProperty_unit(String propertyUnit) {
  property_unit = propertyUnit;
 }
 public Date getNow() {
  return now;
 }
 public void setNow() {
  Date no=new Date(System.currentTimeMillis());
  this.now = no;
 }

    5、在WebContent\META-INF目录下新建xfire文件夹,然后在xfire目录下新建ervices.xml,该配置文件中的内容反映了要将哪些java类发布为web服务。

   

<beans >
<service xmlns="
http://xfire.codehaus.org/config/1.0"
       xmlns:s="
http://www.springframework.org/schema/beans"
        xmlns:xsi="
http://www.w3.org/2001/XMLSchema-instance"
       xsi:schemaLocation="
http://www.springframework.org/schema/beans
        http://www.springframework.org/schema/beans/spring-beans-2.5.xsd">

  <name>InventoryImpl</name>
  <serviceClass>com.yjt.service.Inventory</serviceClass>
  <implementationClass>com.yjt.service.InventoryImpl</implementationClass>

  <style mce_bogus="1">wrapped</style>
  <use>literal</use>
  <scope>application</scope>
  <namespace>http://com.yjt.service/InventoryImpl/</namespace>
 </service>
</beans>

       6、WebContent\WEB-INF目录下新建classes文件夹,然后需要将WebContent下的整个META-INF文件夹剪切到新建的classes文件夹下。
 至此就算是配置完了,右键项目名称->Run As ->Run On Server,关联到你机器上的TomCat,然后会启动Tomcat,以启动web服务。

输入http://localhost:8080/InventoryServer/services/InventoryImpl?wsdl会得到正确的web服务描述文档。

       7、在工程上右键->export->war file ,将这个war fire复制到tomcat的webapp下就可以了。

 

源代码:http://download.csdn.net/detail/zhuimengandyue/5842193

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值