2

您好我想从网络服务返回一个列表。我的代码是

public class WebListTest {
    public List serviceFunction(String arg1,String arg2)
    {
    List list=new ArrayList();
        list.add(arg1);
        list.add(arg2);
            return list;    

        }
}

但是在wsdl创作中我发现

<xs:element minOccurs="0" name="return" nillable="true" type="xs:anyType"/>

当从客户端调用这个网络服务时,我得到了异常

org.apache.axis2.AxisFault: org.apache.axis2.databinding.ADBException: Any type element type has not been given
    at org.apache.axis2.AxisFault.makeFault(AxisFault.java:430)
    at webservice1.WebListTestStub.fromOM(WebListTestStub.java:1622)
    at webservice1.WebListTestStub.serviceFunction(WebListTestStub.java:191)
    at webservice1.ServiceTest.main(ServiceTest.java:24)
Caused by: java.lang.Exception: org.apache.axis2.databinding.ADBException: Any type element type has not been given
    at webservice1.WebListTestStub$ServiceFunctionResponse$Factory.parse(WebListTestStub.java:917)
    at webservice1.WebListTestStub.fromOM(WebListTestStub.java:1616)
    ... 2 more
Caused by: org.apache.axis2.databinding.ADBException: Any type element type has not been given
    at org.apache.axis2.databinding.utils.ConverterUtil.getAnyTypeObject(ConverterUtil.java:1612)
    at webservice1.WebListTestStub$ServiceFunctionResponse$Factory.parse(WebListTestStub.java:895)
    ... 3 more

现在我做什么。请帮忙。

4

2 回答 2

7

从 Axis2 POJO Web 服务对象返回数据时,不应使用 Java 集合类型,而应返回对象数组或原始类型。WSDL 不允许 Java 集合数据结构。请记住,Web 服务需要可以从任何语言访问,并且它们不会使用与 Java 相同的集合框架。

所以,做这样的事情:

public class WebListTest {
    public String[] serviceFunction(String arg1,String arg2) {

    List<String> stringList=new ArrayList<String>();

    stringList.add(arg1);
    stringList.add(arg2);

    return stringList.toArray( new String[stringList.size()] );
    }
}
于 2013-02-21T12:49:29.523 回答
0

您可以将返回类型从 "List" 更改为 "List< String >" ,它会正常工作。

public class WebListTest {
    public List<String> serviceFunction(String arg1,String arg2)
    {
        List<String> list=new ArrayList();
        list.add(arg1);
        list.add(arg2);
        return list;    

    }
}
于 2017-08-10T05:08:30.227 回答