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

首先新建一个工程,取名就随便点啦..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. Android资源--颜色RGB值以及名称及样图

      颜  色    RGB值 英文名 中文名   #FFB6C1 LightPink 浅粉红   #FFC0CB Pink 粉红   #DC143C Crimson 深红/猩红   #FFF0F5 L ...

  2. UITabBar背景、icon图标颜色、被选中背景设置以及隐藏UITabBar的两种方式

    一.对UITabBar背景和icon图标的一些设置 (1)因为直接给UITabBar设置的背景颜色显示的不纯,半透明的感觉,所以,有时候我们可以直接利用纯色的图片作为背景达到想要的效果: (2)给ic ...

  3. EffectiveC#02--仅在对基类进行强制更新时才使用new修饰符

    1.建议避免使用new修饰符来重新定义非虚函数. 非虚方法是静态绑定的,不管哪里的代码也不管在哪里引用, 它总是严格的调用类中所定义的函数.并不会在运行时在 派生类中查找不同的版本. 2.何时使用ne ...

  4. cookie那些事

    本文面向对cookie有基本了解的读者,小白出门左转   设置cookie (HTTP 响应头) Set-Cookie: {name}={value};path={path};domain={doma ...

  5. WIN7系统JavaEE(java+tomcat7+Eclipse)环境配

    在进行 Java Web环境开发之前,首先要做的第一件事就是搭建开发环境,开发环境搭建成功,接下来便是对整个开发环境进行测试,可以通过编写一个简单的JSP 程序发布到Tomcat应用服务器上运行. 1 ...

  6. HTML5 本地裁剪图片并上传至服务器(转)

    很多情况下用户上传的图片都需要经过裁剪,比如头像啊什么的.但以前实现这类需求都很复杂,往往需要先把图片上传到服务器,然后返回给用户,让用户确定裁剪坐标,发送给服务器,服务器裁剪完再返回给用户,来回需要 ...

  7. PHP学习笔记三十三【自定义错误处理器】

    <?php //自定义错误处理器 //$errorno 错误号 //$errmes错误信息 //这两个参数是必须的 function my_error($errorno,$errmes) { e ...

  8. 在 Xcode中 修改文件中自动创建的Created by和Copyright

    在Xcode里创建的时候,会自动生成注释 //  Created byxxx on 15/7/10. //  Copyright (c) 2015年 xxxx. All rights reserved ...

  9. (转) 新手入门:C/C++中的结构体

    本文转载于 http://pcedu.pconline.com.cn/empolder/gj/c/0503/567930_all.html#content_page_1 所有程序经过本人验证,部分程序 ...

  10. Android 开发技术流程

    1.网络连接通信 HttpClient 类通信(见<第一行代码> 郭霖2014.8月第一版P385) Android Asynchronous Http Client  (见  http: ...