博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
使用XFire调用Web服务 测式 案例!
阅读量:7064 次
发布时间:2019-06-28

本文共 3088 字,大约阅读时间需要 10 分钟。

hot3.png

1,在web.xml里配制

XFireServlet
org.codehaus.xfire.transport.http.XFireConfigurableServlet
0
XFireServlet
/services/*
2,在service.xml里配置

BizAccountService
cn.jbit.jboa.ws.BizAccountService
cn.jbit.jboa.ws.BizAccountServiceImpl
literal
application

3,创建包结构,如图

实现类代码如下:

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 List
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"; } }
4,测式类如下:

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("------------");		 //测试反回字集合		List
list=bizAccount.getBizAccount("hello"); if(list!=null){ Account acc=null; for(int i=0;i
OK!

需要注意可能会报错!原因是要替换一个jar包  wstx-asl-3.2.0.jar  换成  wstx-asl-3.2.3.jar

转载于:https://my.oschina.net/pangzhuzhu/blog/301817

你可能感兴趣的文章
小议C#接口的隐式与显示实现
查看>>
CentOS7关闭防火墙
查看>>
步步为营 .NET 设计模式学习笔记 二十四、Factory Method(工厂方法模式)
查看>>
Linux wget auto login and backup database
查看>>
Mysql 外键约束
查看>>
leetcode-169-Majority Element
查看>>
基于HTML5的燃气3D培训仿真系统
查看>>
第八课:SQL数据库插入数据和更新数据
查看>>
自动化测试基础篇--Selenium简介
查看>>
Javascript-Dom-删除
查看>>
sleep()和wait()有什么区别?
查看>>
读取XML文件
查看>>
三、Python-列表
查看>>
查找字符串中出现最多的字符
查看>>
设置c++程序的堆栈空间解决栈溢出问题
查看>>
新手须知 C、C++和VC++之间的区别
查看>>
初学者比较容易犯的布局错误(手风琴布局)
查看>>
【Mybatis】 Mybatis在xml文件中处理大于号小于号的方法【问题】
查看>>
软件开发中的完整测试所包括的环节UT、IT、ST、UAT
查看>>
【Unity Shaders】《Unity Shaders and Effects Cookbook》总结篇
查看>>