xfire+spring整合webservice

服务器端: 

1、建立一个新的项目springXfireWebService (客户端) 

2、在官网http://xfire.codehaus.org/Download中下载:xfire-distribution-1.2.6.zip (在建立项目后将所有jar包放到lib包中,测试删掉几个发现不行,似乎都是需要的,忘高手指明不足)和xfire-all-1.2.6.jar 。 

3、建立webService: 

Java代码   收藏代码
  1. package com.ebiz.xfire.service;  
  2.   
  3. import java.util.List;  
  4.   
  5. import com.ebiz.xfire.domain.CscProject;  
  6.   
  7. /** 
  8.  * @author Ethan,Woo 
  9.  */  
  10. public interface CscWebService {  
  11.   
  12.     /** 
  13.      *@author Ethan,Woo 
  14.      *@desc "加载项目库数据" 
  15.      *@date 2009-09-28 
  16.      */  
  17.     List<CscProject> getCscProjectList(CscProject t);  
  18.   
  19.       
  20. }  


4、实现: 

Java代码   收藏代码
  1. package com.ebiz.xfire.service.impl;  
  2.   
  3. import com.ebiz.xfire.service.WyWebService;  
  4.   
  5. /** 
  6.  * @author Ethan,Woo 
  7.  */  
  8. public class WyWebServiceImpl implements WyWebService {  
  9.   
  10.     public void printHello() {  
  11.         System.out.println("Hello!");  
  12.     }  
  13.   
  14. }  


5、引入jar包:xfire-distribution-1.2.6.zip 里面的包、xfire-all-1.2.6.jar和spring-2.5.6.jar。 

6、与spring整合spring-context.xml: 

Xml代码   收藏代码
  1. <?xml version="1.0" encoding="UTF-8"?>  
  2. <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"  
  3.     xmlns:p="http://www.springframework.org/schema/p" xmlns:context="http://www.springframework.org/schema/context"  
  4.     xmlns:jee="http://www.springframework.org/schema/jee" xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx"  
  5.     xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd  
  6.                 http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd  
  7.                 http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.5.xsd  
  8.                 http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-2.5.xsd  
  9.                 http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd"  
  10.     default-autowire="byName">  
  11.   
  12.     <import resource="classpath:org/codehaus/xfire/spring/xfire.xml" />  
  13.   
  14.     <!-- ====================testSpringXfire================= -->  
  15.     <bean id="wyWebServiceImpl" class="com.ebiz.xfire.service.impl.WyWebServiceImpl" />  
  16.     <bean id="addressingHandler" class="org.codehaus.xfire.addressing.AddressingInHandler" />  
  17.     <bean name="webService" class="org.codehaus.xfire.spring.ServiceBean">  
  18.         <property name="serviceBean" ref="wyWebServiceImpl"></property>  
  19.         <property name="serviceClass" value="com.ebiz.xfire.service.WyWebService"></property>  
  20.         <property name="inHandlers">  
  21.             <list>  
  22.                 <ref bean="addressingHandler" />  
  23.             </list>  
  24.         </property>  
  25.     </bean>  
  26.   
  27. </beans>  


7、配置web.xml: 

Xml代码   收藏代码
  1. <?xml version="1.0" encoding="UTF-8"?>  
  2. <web-app id="WebApp_ID" version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"  
  3.     xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">  
  4.     <display-name>XFireTest</display-name>  
  5.     <welcome-file-list>  
  6.         <welcome-file>index.html</welcome-file>  
  7.         <welcome-file>index.jsp</welcome-file>  
  8.     </welcome-file-list>  
  9.   <context-param>   
  10.     <param-name>contextConfigLocation</param-name>   
  11.     <param-value>classpath:spring-context.xml</param-value>   
  12.   </context-param>   
  13.   <listener>   
  14.     <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>   
  15.   </listener>   
  16.   <servlet>   
  17.     <servlet-name>XFireServlet</servlet-name>   
  18.     <servlet-class>org.codehaus.xfire.spring.XFireSpringServlet</servlet-class>   
  19.   </servlet>   
  20.   <servlet-mapping>   
  21.     <servlet-name>XFireServlet</servlet-name>   
  22.     <url-pattern>/servlet/XFireServlet/*</url-pattern>   
  23.   </servlet-mapping>   
  24.   <servlet-mapping>   
  25.     <servlet-name>XFireServlet</servlet-name>   
  26.     <url-pattern>/services/*</url-pattern>   
  27.   </servlet-mapping>   
  28. </web-app>  


8、启动项目springXfireWebService (客户端),没有出错 第一步OK啦!!  

客户端: 

1、建立新的项目springXfireClient(客户端) 

2、建立service: 

Java代码   收藏代码
  1. package com.ebiz.xfire.service;  
  2.   
  3.   
  4. /** 
  5.  * @author Ethan,woo 
  6.  * @version 2009-09-28 
  7.  */  
  8. public interface WyWebService {  
  9.   
  10.     /** 
  11.      *@desc "打印Hello" 
  12.      */  
  13.      void printHello();  
  14.   
  15. }  


Java代码   收藏代码
  1. 注意:这里的包的目录结构一定要和客户端的包的结构一定要一样(本人吃过亏的~~~~(>_<)~~~~ )  


3、建立test.java 

Java代码   收藏代码
  1. package com.testxfire.client;  
  2.   
  3. import java.net.MalformedURLException;  
  4.   
  5. import org.codehaus.xfire.XFireFactory;  
  6. import org.codehaus.xfire.client.XFireProxyFactory;  
  7. import org.codehaus.xfire.service.Service;  
  8. import org.codehaus.xfire.service.binding.ObjectServiceFactory;  
  9.   
  10. import com.ebiz.xfire.service.WyWebService;  
  11.   
  12. public class Test {  
  13.   
  14.     public static void main(String[] args) {  
  15.   
  16.         Service serviceModel = new ObjectServiceFactory().create(WyWebService.class);  
  17.   
  18.         XFireProxyFactory factory = new XFireProxyFactory(XFireFactory.newInstance().getXFire());  
  19.   
  20.         String url = "http://localhost:8080/springXfireWebService/services/WyWebService";  
  21.         try {  
  22.             WyWebService cws = (WyWebService) factory.create(serviceModel, url);  
  23.             cws.printHello();  
  24.   
  25.         } catch (MalformedURLException e) {  
  26.             e.printStackTrace();  
  27.         }  
  28.   
  29.     }  
  30.   
  31. }  


4、在控制台出现: 

Hello 

完成。注意这里没有涉及到与数据库的交互,可以在实现中完善,另外在在spirng中配置。
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值