我把这个创建的步骤和代码的贴出来,.

首先新建一个工程,取名就随便点啦..MyWebService,然后复制jar包到lib目录下, 创建包,建立接口..写一个javaBean的类,

以下是一个简单的不能再简单的接口了,

  1. package pack.java.xfire.demo;
  2. import java.util.List;
  3. /**
  4. * @author Administrator
  5. * 服务端接口;
  6. */
  7. public interface IPerson {
  8. public abstract List<Person> getPersonList();
  9. public abstract List<Person> setPersonList(List<Person> personList);
  10. public abstract Person getPersonObj();
  11. }

接下来就是实现这个接口:

  1. package pack.java.xfire.demo;
  2. import java.io.Serializable;
  3. import java.util.ArrayList;
  4. import java.util.HashMap;
  5. import java.util.List;
  6. import java.util.Map;
  7. /**
  8. * Service 端,实现类;
  9. * @author Administrator
  10. *
  11. */
  12. public class PersonImpl implements IPerson,Serializable{
  13. private static final long serialVersionUID = -9034712983379559694L;
  14. public List<Person> getPersonList(){
  15. List<Person> list=new ArrayList<Person>();
  16. Person person=new Person();
  17. person.setAge(22);
  18. person.setName("Zhou");
  19. person.setSex("Boy");
  20. list.add(person);
  21. Person person2=new Person();
  22. person2.setAge(19);
  23. person2.setName("Peng");
  24. person2.setSex("Girl");
  25. list.add(person2);
  26. return list;
  27. }
  28. public Person getPersonObj(){
  29. Person person=new Person();
  30. person.setAge(22);
  31. person.setName("ZengPing");
  32. person.setSex("Girl");
  33. Map<Integer, String> map=new HashMap<Integer, String>();
  34. map.put(1, "HuFang");
  35. map.put(2, "DuanYouYu");
  36. map.put(3, "TianWei");
  37. List<String> list=new ArrayList<String>();
  38. list.add("List1");
  39. list.add("List2");
  40. list.add("List3");
  41. person.setList(list);
  42. person.setMap(map);
  43. return person;
  44. }
  45. public List<Person> setPersonList(List<Person> personList){
  46. return personList;
  47. }
  48. }

之后,在你的工程的src目录下建立,META-INF/xfire/services.xml文件,其内容如下:

  1. <?xml version="1.0" encoding = "utf-8" ?>
  2. <beans xmlns="http://xfire.codehaus.org/config/1.0">
  3. <service>
  4. <name>PersonService</name>
  5. <namespace>http://simple.java.xifire/IPerson</namespace>
  6. <serviceClass>pack.java.xfire.demo.IPerson</serviceClass>
  7. <implementationClass>pack.java.xfire.demo.PersonImpl</implementationClass>
  8. <scope>request</scope>
  9. </service>
  10. </beans>

在启动web 服务器, 在浏览器中输入:

http://localhost:8080/XFireServices/services/

之后就能看到

Available Services:

  • PersonService [wsdl]<!--Just filling space according to http://support.microsoft.com/default.aspx?scid=kb;en-us;Q294807--><!--Just filling space according to http://support.microsoft.com/default.aspx?scid=kb;en-us;Q294807-->

点击进去之后,自动产生的一个对应的一些xml配置文件..

配置客户端:

1.建立客户端工程, 拷贝jar包到lib目录下, 然后建立包 和 接口,JavaBean等等, 这里说明一点:

客户端建立的包和接口一样要和服务器端的接口和类一摸一样,还有服务器端的javaBean必须实现Serializable,才能够传输.

否则会找不到,对应的文件, 从服务器返回过来的数据会为null;

在写一个测试类,用来测试服务器的返回的数据,

  1. package pack.java.xfire.demo;
  2. import java.net.MalformedURLException;
  3. import java.util.ArrayList;
  4. import java.util.Iterator;
  5. import java.util.List;
  6. import java.util.Map;
  7. import org.codehaus.xfire.client.XFireProxyFactory;
  8. import org.codehaus.xfire.service.Service;
  9. import org.codehaus.xfire.service.binding.ObjectServiceFactory;
  10. /**
  11. * Client 测试端;
  12. * @author Administrator
  13. *
  14. */
  15. public class ClientDemo {
  16. /**
  17. * 主方法;
  18. * @param args
  19. */
  20. public static void main(String[] args) {
  21. // TODO Auto-generated method stub
  22. String  url="http://PC2009120421osa:8080/XFireServices/services/PersonService";
  23. Service serviceModel=new ObjectServiceFactory().create(IPerson.class);
  24. try {
  25. IPerson person=(IPerson) new XFireProxyFactory().create(serviceModel, url);
  26. List<Person> list=person.getPersonList();
  27. //输出Person list集合;
  28. for(Person per:list){
  29. System.out.println(per.getName()+","+per.getAge()+","+per.getSex());
  30. }
  31. List<Person> list2=new ArrayList<Person>();
  32. Person person2=new Person();
  33. person2.setAge(11);
  34. person2.setName("Test");
  35. person2.setSex("Girl");
  36. list2.add(person2);
  37. //设置Person list集合;
  38. List<Person> personList2=person.setPersonList(list2);
  39. //输出从服务器端返回的集合数据;
  40. for (Person per : personList2) {
  41. System.out.println("\n"+per.getName()+","+per.getAge()+","+per.getSex());
  42. }
  43. //调用服务器端的单个对象;
  44. Person person3 =person.getPersonObj();
  45. System.out.println("\n"+person3.getName()+","+person3.getAge()+","+person3.getSex());
  46. Map<Integer,String> map=person3.getMap();
  47. System.out.println("\n服务器端返回的List集合");
  48. List<String> list3=person3.getList();
  49. for (String str : list3) {
  50. System.out.println(str);
  51. }
  52. System.out.println("\n服务器端返回的Map集合");
  53. for(Iterator<Integer> iterator=map.keySet().iterator();iterator.hasNext();){
  54. int resultKey=iterator.next();
  55. String resultValue=map.get(resultKey);
  56. System.out.println(resultKey+","+resultValue);
  57. }
  58. } catch (MalformedURLException e) {
  59. // TODO Auto-generated catch block
  60. e.printStackTrace();
  61. }
  62. }
  63. }

控制台输出的结果如下:代表成功..

-----------------------------------------------------------------------

Zhou,22,Boy
Peng,19,Girl

Test,11,Girl

ZengPing,22,Girl

服务器端返回的List集合
List1
List2
List3

服务器端返回的Map集合

Web Service中的XFire 传输List 自定义对象.的更多相关文章

  1. Web Service 中返回DataSet结果大小改进

    http://www.cnblogs.com/scottckt/archive/2012/11/10/2764496.html Web Service 中返回DataSet结果方法: 1)直接返回Da ...

  2. 在Web Service中傳送Dictionary

    有個需求,想在Web Service中傳遞Dictionary<string, string>參數,例如: 排版顯示純文字 [WebMethod] public Dictionary< ...

  3. Web Service 中返回DataSet结果的几种方法

    Web Service 中返回DataSet结果的几种方法: 1)直接返回DataSet对象    特点:通常组件化的处理机制,不加任何修饰及处理:    优点:代码精减.易于处理,小数据量处理较快: ...

  4. ASP.NET Web Service中使用Session 及 Session丢失解决方法 续

    原文:ASP.NET Web Service中使用Session 及 Session丢失解决方法 续 1.关于Session丢失问题的说明汇总,参考这里 2.在Web Servcie中使用Sessio ...

  5. 问题:不支持Dictionary;结果:在Web Service中傳送Dictionary

    在Web Service中傳送Dictionary 有個需求,想在Web Service中傳遞Dictionary<string, string>參數,例如: 排版顯示純文字 [WebMe ...

  6. HashSet存储过程中如何排除不同的自定义对象?

    HashSet HashSet存储过程中如何排除不同的自定义对象? 先看一个小demo public class Demo1 { public static void main(String[] ar ...

  7. 转-Web Service中三种发送接受协议SOAP、http get、http post

    原文链接:web服务中三种发送接受协议SOAP/HTTP GET/HTTP POST 一.web服务中三种发送接受协议SOAP/HTTP GET/HTTP POST 在web服务中,有三种可供选择的发 ...

  8. 企业级SOA之路——在Web Service中使用HTTP和JMS

    原文:http://www.tibco.com/resources/solutions/soa/enterprise_class_soa_wp.pdf   概述     IT业界在早期有一种误解,认为 ...

  9. Web Service中的几个重要术语

    WSDL:web service definition language 直译:WebService定义语言 1.对应一种该类型的文件.WSDL 2.定义了Web Service的服务器与客户端应用交 ...

随机推荐

  1. [转]Binarized Neural Networks_ Training Neural Networks with Weights and Activations Constrained to +1 or −1

    原文: 二值神经网络(Binary Neural Network,BNN) 在我刚刚过去的研究生毕设中,我在ImageNet数据集上验证了图像特征二值化后仍然具有很强的表达能力,可以在检索中达到较好的 ...

  2. Linux下使用JNI的常见问题及解决方案

    JNI是java和C/C++混合编程的接口,可以很方便地实现java调用C/C++语言.具体的使用方法,网上有很多教程,在此不做过多介绍.本博客只关注在使用JNI的过程中的常见问题. 1.     生 ...

  3. java实现各种数据统计图(柱形图,饼图,折线图)

    近期在做数据挖掘的课程设计,须要将数据分析的结果非常直观的展现给用户,这就要用到数据统计图,要实现这个功能就须要几个第三方包了: 1.       jfreechart-1.0.13.jar 2.   ...

  4. [每日一题] OCP1z0-047 :2013-08-17 EXTERNAL TABLE――加载数据 ............................56

    正确答案:C 一.对答案解释: A.       TYPE:有两个选可供选择: 1.        ORACLE_LOADER:传统方式,与SQLLDR一样,参数从多,应用较多. 2.         ...

  5. [转]CSS vertical-align属性详解 作者:黄映焜

      CSS vertical-align属性详解 posted @ 2014-08-26 17:44 黄映焜   前言:关于vertical-align属性. 实践出真知. 垂直居中. 第二种用法. ...

  6. Android SDK代理服务器解决国内不能更新下载问题(转)

    言:Android SDK代理服务器解决国内Android SDK不能更新下载问题,经常会遇到Fitch fail URL错误,要不就是Nothing was installed.目下Google遭受 ...

  7. (转)swfobject.js 详细解说

    一直想对这个应用做个总结,今天偶然百度到这个效果,为此做个笔记. 用这个js的好处: 1.IE中没有讨厌的虚框问题了.2.提供了完善的版本检测功能,如果版本不够则显示其他东西,比如图片或文字.3.易于 ...

  8. 13年山东省赛 Mountain Subsequences(dp)

    转载请注明出处: http://www.cnblogs.com/fraud/          ——by fraud Mountain Subsequences Time Limit: 1 Sec   ...

  9. AnyWhere

    anyexec_date 201506171258 anyexec_date @@AnyWhereCmd idc python /home/appadmin/nicker/tools/QUI.py m ...

  10. Spring的PropertyPlaceholderConfigurer应用

    Spring 利用PropertyPlaceholderConfigurer占位符 1. PropertyPlaceholderConfigurer是个bean工厂后置处理器的实现,也就是BeanFa ...