首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > Web Service >

客户端调用webservice接口返回值为null有关问题~

2013-03-10 
客户端调用webservice接口返回值为null问题~!!!!package testimport java.io.Serializablepublic class

客户端调用webservice接口返回值为null问题~!!!!

package test;

import java.io.Serializable;

public class Course implements Serializable{
    /**
 * 
 */
private static final long serialVersionUID = 1L;
private String name;

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

}


package test;

import java.io.Serializable;

public class User implements Serializable{
    /**
 * 
 */
private static final long serialVersionUID = 1L;
private String name;

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }
}



以上是用的的俩个实体类 User和Course


package  test;

  import  java.util.List;
  
   public   interface  IHelloService   {
      public  String sayHello(String ttt);
     
      public  Course choose(User u);
     
      public  List  test(List t);
 }

这是接口 文件名:IHelloService


package test;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

public class HelloServiceImpl implements IHelloService,Serializable {

    /**
 * 
 */
private static final long serialVersionUID = 1L;

public String sayHello(String ttt) {
        return "Hello, "+ttt;
    }
    
    public Course choose(User u){
        System.out.println("u.getname-------------->"+u.getName());
        Course c=new Course();
       // c.setName("Eeee");
        System.out.println(c.getName());
        return c; 
        
    }
    
    public List  test(List t){
        for (int i = 0; i < t.size(); i++) {
            System.out.println("t的第"+i+"个--------------->"+(String) t.get(i));
        }
        List  al=new ArrayList();


        Course c=new Course();
        //c.setName("EeeDDDDDD");
        al.add(c);
        return al;
        
    }
}


这是接口实现类 文件名:HelloServiceImpl



<?xml version="1.0" encoding="UTF-8"?>
<mappings>
    <mapping>
        <method name="test">
            <parameter index="0" componentType="java.lang.String" />
            <return-type componentType="test.Course" />
        </method>
    </mapping>
</mappings>

这是XML文件 文件名 IHelloService.aegis.xml



<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://xfire.codehaus.org/config/1.0">

    <service>
        <name>HelloService</name>
        <namespace>http://test/HelloService</namespace>
        <serviceClass>test.IHelloService</serviceClass>
        <implementationClass>test.HelloServiceImpl</implementationClass>
        <style>wrapped</style>
<use>literal</use>
<scope>application</scope>
    </service>
    
</beans>

这是services.xml文件




<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="2.5" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee   http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
  <servlet>
    <servlet-name>XFireServlet</servlet-name>
    <servlet-class>org.codehaus.xfire.transport.http.XFireConfigurableServlet</servlet-class>
    <load-on-startup>0</load-on-startup>
  </servlet>
  
  <servlet-mapping>
        <servlet-name>XFireServlet</servlet-name>
        <url-pattern>/servlet/XFireServlet/*</url-pattern>
    </servlet-mapping>
  
  <servlet-mapping>
    <servlet-name>XFireServlet</servlet-name>
    <url-pattern>/services/*</url-pattern>
  </servlet-mapping>
  <welcome-file-list>
    <welcome-file>index.jsp</welcome-file>
  </welcome-file-list>
</web-app>

这是web.xml文件

以上是webservice接口



package com.client;
import java.net.MalformedURLException;
import java.util.ArrayList;
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;

public class testClient {

    public static void main(String[] args) {

        Service srvcModel = new ObjectServiceFactory()
                .create(IHelloService.class);
        XFireProxyFactory factory = new XFireProxyFactory(XFireFactory
                .newInstance().getXFire());

        String helloWorldURL = "http://localhost:8080/testWebService/services/HelloService";
        try {
            IHelloService srvc = (IHelloService) factory.create(srvcModel,
                    helloWorldURL);
            System.out.println(srvc.sayHello("Robin"));
            
            User u=new User();
            u.setName("RRRRR");
            Course c = srvc.choose(u);
            //System.out.println(srvc.choose(u));
            System.out.println(c.getName());
            
            List  t=new ArrayList();
            t.add("1212");
            t.add("2222");
            List al=srvc.test(t);
            System.out.println(al.size());
            for (int i = 0; i < al.size(); i++) {
                Course co=(Course)al.get(i);
                System.out.println(co.getName());
            }
            
            
        } catch (MalformedURLException e) {
            e.printStackTrace();
        }

    }

}


这是写在一个java项目里面的一个测试类,运行后

Hello, Robin
null
1
null   
控制台输出以上内容

服务端输出如下:
u.getname-------------->null
null
t的第0个--------------->1212
t的第1个--------------->2222


请问为什么传进去的自定义对象参数在服务端会变成NULL,而集合却能接受,而且服务端返回给客户端的则全是null,但是集合能获得大小。。。。纠结好久了。。。求高手们给指点指点


[解决办法]
晕,你干脆把你项目传上去让高手帮忙解决吧,你光把代码传了架构没有啊
[解决办法]
具体问题出在哪?

热点排行