1,在web.xml里配制
2,在service.xml里配置XFireServlet org.codehaus.xfire.transport.http.XFireConfigurableServlet 0 XFireServlet /services/*
3,创建包结构,如图BizAccountService cn.jbit.jboa.ws.BizAccountService cn.jbit.jboa.ws.BizAccountServiceImpl application
实现类代码如下:
package cn.jbit.jboa.ws;import java.util.ArrayList;import java.util.Date;import java.util.List;import org.codehaus.xfire.transport.http.XFireConfigurableServlet;import sun.org.mozilla.javascript.internal.Synchronizer;import cn.jbit.jbos.bean.Account;public class BizAccountServiceImpl implements BizAccountService { public List4,测式类如下:getBizAccount(String str) { System.out.println(str.trim()); List list=new ArrayList (); Account a1=new Account(); a1.setId(1); a1.setAcc_money(500); a1.setAcc_time(new Date()); a1.setAcc_type('0'); a1.setSheet_id(11); a1.setUsr_id(110); Account a2=new Account(); a2.setId(2); a2.setAcc_money(1500); a2.setAcc_time(new Date()); a2.setAcc_type('0'); a2.setSheet_id(11); a2.setUsr_id(110); Account a3=new Account(); a3.setId(3); a3.setAcc_money(3500); a3.setAcc_time(new Date()); a3.setAcc_type('0'); a3.setSheet_id(11); a3.setUsr_id(110); list.add(a1); list.add(a2); list.add(a3); System.out.println(list.size()+" 返回了"); return list; } public String testHello() { System.out.println("hello! testHello--------------"); try { Thread.sleep(5000); } catch (InterruptedException e) { // TODO Auto-generated catch block e.printStackTrace(); } return "world"; } }
package cn.jbjt.jboa.ws.client;import java.util.List;import org.codehaus.xfire.XFireFactory;import org.codehaus.xfire.client.XFireProxyFactory;import org.codehaus.xfire.service.Service;import org.codehaus.xfire.service.binding.ObjectServiceFactory;import cn.jbit.jboa.ws.BizAccountService;import cn.jbit.jbos.bean.Account;public class BizAccountSClient { /** * @param args * @throws InterruptedException */ public static void main(String[] args) { //创建服务接口模版 Service serviceModel=new ObjectServiceFactory(). create(BizAccountService.class); //创建代理工厂 XFireProxyFactory factory= new XFireProxyFactory(XFireFactory.newInstance().getXFire()); //定义web服务地址 String accuntServicURL="http://localhost:8080/LedgerWebService/" + "services/BizAccountService"; try { //根据接口模板和Web服务地址返回服务类 BizAccountService bizAccount= (BizAccountService) factory. create(serviceModel,accuntServicURL); //根据参数调用方法,并反回结果 //测试反回字符串 String str=bizAccount.testHello(); System.out.println(str+"------------"); System.out.println("------------"); //测试反回字集合 ListOK!list=bizAccount.getBizAccount("hello"); if(list!=null){ Account acc=null; for(int i=0;i
需要注意可能会报错!原因是要替换一个jar包 wstx-asl-3.2.0.jar 换成 wstx-asl-3.2.3.jar