---
title: "XFire+Spring发布Web Service（一）"
author: "benniaolk"
date: "2009-12-10T20:38:50Z"
tags: []
categories: ["编程语言"]
slug: "xfire-spring-web-service"
draft: false
lastmod: "2009-12-10T21:09:52Z"
id: 545826
url: "https://dreava.iteye.com/blog/545826"
---

XFire的介绍另见学习资料。  
该文档包含了多种Web服务的发布，主要演示复杂对象的传递——网上很多有关Web Services的发布教程讲到的都只是简单的Hello World，在调用Web Service的时候，返回值都是以字符串做演示，都没有涉及到复杂对象的传递。通过该文档，应该可以应付所有的传递值类型了，除了java.util.Map类型 的对象。具体原因，据网上所说，是因为XFire还是什么咚咚与WSDL的xsd:anyType的映射有缺陷引起的。  
**1.发布Web Service的接口**  
言归正传，下面是用来发布Web Services的接口及实现类：

**package** demo;

 

**import** java.util.Collection;

**import** java.util.List;

 

/\**

 * 用于发布Web Service的接口

 * **@author** dreava Nov 10, 2008

 \*/

**public** **interface** IHelloService {

    /\**

     * **@param** ttt

     * **@return**

     \*/

    **public** String sayHello(String ttt);

 

    /\**

     * **@param** u

     * **@return**

     \*/

    **public** Course choose(User u);

 

    /\**

     * **@param** t

     * **@return**

     \*/

    **public** List&lt;Course&gt; getList(List&lt;String&gt; paramList);

   

    /\**

     * **@return**

     \*/

    **public** Collection&lt;User&gt; getCollection();

}

 

 

 

 

**package** demo;

 

**import** java.util.ArrayList;

**import** java.util.Collection;

**import** java.util.HashSet;

**import** java.util.List;

 

/\**

 * **@author** dreava Nov 10, 2008

 \*/

**public** **class** HelloServiceImpl **implements** IHelloService {

    **public** String sayHello(String ttt) {

        **return** "Hello, " + ttt;

    }

 

    **public** Course choose(User user) {

        System.*out*.println(user.getName());

        Course course = **new** Course();

        course.setName("choose: Eee");

        List&lt;User&gt; userList = **new** ArrayList&lt;User&gt;();

        userList.add(user);

       

        course.setUserList(userList);

        **return** course;

    }

 

    **public** List&lt;Course&gt; getList(List&lt;String&gt; paramList) {

        **for** (**int** i = 0; i &lt; paramList.size(); i++) {

            System.*out*.println((String) paramList.get(i));

        }

        List&lt;Course&gt; courseList = **new** ArrayList&lt;Course&gt;();

        Course course = **new** Course();

        course.setName("getList: EeeDDDDDD");

        User user = **new** User();

        user.setName("getList: liaokun");

        List&lt;User&gt; userList = **new** ArrayList&lt;User&gt;();

        userList.add(user);

        course.setUserList(userList);

       

        courseList.add(course);

        **return** courseList;

    }

   

    **public** Collection&lt;User&gt; getCollection(){

        Collection&lt;User&gt; collection = **new** HashSet&lt;User&gt;();

        **for** (**int** i = 0; i &lt; 5; i++) {

            User user = **new** User();

            user.setName("user"+i);

            collection.add(user);

        }

       

        **return** collection;

         

    }

}

 

下面是上述接口和实现类涉及到的POJO类：

**package** demo;

 

**import** java.util.Collection;

**import** java.util.List;

**import** java.util.Map;

**import** java.util.Set;

 

/\**

 * **@author** dreava Nov 10, 2008

 \*/

**public** **class** Course {

    **private** String name;

   

    **private** List&lt;User&gt; userList;

   

    **public** Collection&lt;User&gt; collection;

 

    **public** Collection&lt;User&gt; getCollection() {

        **return** collection;

    }

 

    **public** **void** setCollection(Collection&lt;User&gt; collection) {

        **this**.collection = collection;

    }

 

    **public** String getName() {

        **return** name;

 

    }

 

    **public** **void** setName(String name) {

        **this**.name = name;

    }

 

    **public** List&lt;User&gt; getUserList() {

        **return** userList;

    }

 

    **public** **void** setUserList(List&lt;User&gt; userList) {

        **this**.userList = userList;

    }

}

 

 

**package** demo;

 

/\**

 * **@author** dreava Nov 10, 2008

 \*/

**public** **class** User {

    **private** String name;

 

    **public** String getName() {

        **return** name;

 

    }

 

    **public** **void** setName(String name) {

        **this**.name = name;

    }

}

 

 

由于文章长度限制，余下部分见XFire+Spring发布Web Service（二）