本帖最后由 maskiris 于 2011-09-16 09:18:09 编辑

解决方案 »

  1.   

    已解决了。在服务端和客户端两个spring配置文件加上相应的实体bean就OK了。
      

  2.   

    今天又开始报错了。在spring配置文件加了bean也不行。郁闷啊~有没有谁知道怎么回事?
    服务端实体对象:public class LineName implements java.io.Serializable {
    private String lineid;
    private String linename;
            //getter and setter....
    }
    实体集对象,包装对象集:@XmlAccessorType(XmlAccessType.FIELD)   
    @XmlType(name = "Lines")
    public class Lines{
        private List<LineName> lines;   
        private LineName[] lineArr;   
        private HashMap<String, LineName> maps;        
     //getter and setter....
    List对象,包装ArrayList:@XmlAccessorType(XmlAccessType.FIELD)   
    @XmlType(name = "listObject", propOrder = { "list" })  
    public class ListObject {
    @XmlElement(nillable = true)   
        protected List<Object> list;   
        public List<Object> getList() {   
            if (list == null) {   
                list = new ArrayList<Object>();   
            }   
            return this.list;
        }   
      
        public void setList(ArrayList<Object> list) {   
            this.list = list;   
        }   
    }
    服务接口:@WebService
    public interface ITicketing_Service {
        public ArrayList getLineAndStationList(String type,String str,String nc);
    }
    服务实现类:public ListObject getLineAndStationList(String type, String str,String nc) {
    ArrayList<Object> list = new ArrayList<Object>();
    TicketService_Logic logic = new TicketService_Logic();
    Lines l = new Lines();
    if(type.equals("1")){
    //list = logic.getLineList(str);
    List<LineName> lines = new ArrayList<LineName>();
    for(int i=0;i<10;i++){

    LineName line = new LineName();
    line.setLineid("0001"+i);
    line.setLinename("北京线"+i);
    lines.add(line);
    }
    l.setLines(lines);
    list.add("0");
    list.add(l);
    }
    ListObject listObject = new ListObject();
    listObject.setList(list);
    return listObject;
    }
    客户端调用服务代码:public class TicketServiceClient {
    public static void main(String[] args){
    TicketServiceClient.doSpringClient();
    // System.out.println(TicketServiceClient.doNormalClient("Michael",90));
    }
    private static ArrayList doSpringClient(){
    // 加载客户端的配置定义
    ApplicationContext context = 
    new FileSystemXmlApplicationContext("src/com/ws/client/beanRefClient.xml");
    // 获取定义的 Web Service Bean
    ITicketing_Service ticketingService = (ITicketing_Service)context.getBean("ticketServiceClient");
    //1
    ListObject l1 = (ListObject) ticketingService.getLineAndStationList("1", "", "");
            List<Object> linesinfo = l1.getList();
            System.out.println(linesinfo.get(0));
            Lines lines = (Lines) linesinfo.get(1);
            for (LineName line : lines.getLines()) {
              System.out.println(line.getLineid());
              System.out.println(line.getLinename());     
            }
    }
    服务端spring配置文件:beanRefServer.xml<beans xmlns="http://www.springframework.org/schema/beans" 
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
        xmlns:jaxrs="http://cxf.apache.org/jaxrs" 
        xmlns:util="http://www.springframework.org/schema/util" 
        xmlns:jaxws="http://cxf.apache.org/jaxws"
        xsi:schemaLocation=" 
    http://www.springframework.org/schema/beans
    http://www.springframework.org/schema/beans/spring-beans.xsd
    http://cxf.apache.org/jaxrs
    http://cxf.apache.org/schemas/jaxrs.xsd
    http://cxf.apache.org/jaxws 
    http://cxf.apache.org/schemas/jaxws.xsd
    http://www.springframework.org/schema/util 
    http://www.springframework.org/schema/util/spring-util-2.0.xsd" 
        default-lazy-init="false">

        <!-- Import Apache CXF Bean Definition -->
        <import resource="classpath:META-INF/cxf/cxf.xml"/>
        <import resource="classpath:META-INF/cxf/cxf-extension-soap.xml"/>
        <import resource="classpath:META-INF/cxf/cxf-servlet.xml"/>    <jaxws:endpoint id="ticketing_Service" 
         implementor="com.ws.server.impl.Ticketing_Service" 
         address="/Ticketing_Service" />
        
        <bean id="Lines" name="Lines" class="com.ws.server.entity.Lines"></bean>
        <bean id="Stations" name="Stations" class="com.ws.server.entity.Stations"></bean>
        <bean id="Sellagents" name="Sellagents" class="com.ws.server.entity.Sellagents"></bean>
        <bean id="Waitstations" name="Waitstations" class="com.ws.server.entity.Waitstations"></bean>
        <bean id="BusSeats" name="BusSeats" class="com.ws.server.entity.BusSeats"></bean>
        <bean id="PricesTypes" name="PricesTypes" class="com.ws.server.entity.PricesTypes"></bean>
        <bean id="BusPrices" name="BusPrices" class="com.ws.server.entity.BusPrices"></bean>
        <bean id="TicketBuses" name="TicketBuses" class="com.ws.server.entity.TicketBuses"></bean>
    </beans>
    客户端spring配置文件:beanRefClient.xml<beans xmlns="http://www.springframework.org/schema/beans"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xmlns:jaxws="http://cxf.apache.org/jaxws"
        xsi:schemaLocation="
            http://www.springframework.org/schema/beans 
            http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
            http://cxf.apache.org/jaxws 
            http://cxf.apache.org/schemas/jaxws.xsd">
        <!-- Import Apache CXF Bean Definition -->
        <import resource="classpath:META-INF/cxf/cxf.xml"/>
        <!-- <import resource="classpath:META-INF/cxf/cxf-extension-soap.xml"/> -->   
        <import resource="classpath:META-INF/cxf/cxf-servlet.xml"/>

        <!-- Ticketing_Service Client -->
        <jaxws:client id="ticketServiceClient"
         serviceClass="com.ws.server.ITicketing_Service" 
         address="http://localhost:8888/NewPtmanager/Ticketing_Service"/>
        
        <bean id="Lines" name="Lines" class="com.ws.server.entity.Lines"></bean>
        <bean id="Stations" name="Stations" class="com.ws.server.entity.Stations"></bean>
        <bean id="Sellagents" name="Sellagents" class="com.ws.server.entity.Sellagents"></bean>
        <bean id="Waitstations" name="Waitstations" class="com.ws.server.entity.Waitstations"></bean>
        <bean id="BusSeats" name="BusSeats" class="com.ws.server.entity.BusSeats"></bean>
        <bean id="PricesTypes" name="PricesTypes" class="com.ws.server.entity.PricesTypes"></bean>
        <bean id="BusPrices" name="BusPrices" class="com.ws.server.entity.BusPrices"></bean>
        <bean id="TicketBuses" name="TicketBuses" class="com.ws.server.entity.TicketBuses"></bean></beans>