一个服务返回一个ArrayList,如何使用Axis序列化/反序列化啊
我的代码如下:
这是发布到服务器上面的代码:
package com;
import java.util.*;
public class ArrayListService {
public ArrayList myAL(){
ArrayList<String> myAL = new ArrayList<String>();
String str=new String("这是一个WebService Of ArrayList !");
myAL.add(str);
return myAL;
}}
客户端的代码:
package com;
import org.apache.axis.client.Call;
import org.apache.axis.client.Service;
import java.util.*;
public class ArrayListClient {
public static void main(String[] args) {
try {
String wsdlUrl = "http://127.0.0.1:8080/axis/services/ArrayListService?wsdl";
Service service = new Service();
Call call = null;
call = (Call) service.createCall();
call.setOperationName("myAL");
call.setTargetEndpointAddress(new java.net.URL(wsdlUrl));
//ArrayList al=(ArrayList)call.invoke(new Object[] {});
call.invoke(new Object[] {});
System.out.println("请求信息:");
call.getMessageContext().getRequestMessage().writeTo(System.out);
System.out.println("");
System.out.println("响应信息:");
call.getMessageContext().getResponseMessage().writeTo(System.out);
System.out.println("");
}
catch (Exception ex) { ex.printStackTrace(); }}}
打印出来的请求和响应消息也正常。
可是服务器返回的是一个ArrayList,当用这一句时“ArrayList al=(ArrayList)call.invoke(new Object[] {});”就报错:
java.lang.ClassCastException: [Ljava.lang.Object;
at com.ArrayListClient.main(ArrayListClient.java:17)
这是什么原因啊,如何把响应消息里面的数据返回成ArrayList呢?
注:server-config.wsdd
<service name="ArrayListService" provider="java:RPC">
<parameter name="className" value="com.ArrayListService"/>
<parameter name="allowedMethods" value="*"/>
<requestFlow>
<handler type="loging"/>
</requestFlow>
<responseFlow>
<handler type="loging"/>
</responseFlow>
</service>
这是服务响应消息:
<?xml version="1.0" encoding="utf-8"?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<soapenv:Body>
<myALResponse soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
<myALReturn href="#id0"/>
</myALResponse>
<multiRef id="id0" soapenc:root="0" soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" soapenc:arrayType="xsd:anyType[1]" xsi:type="soapenc:Array" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/">
<multiRef xsi:type="soapenc:string">这是一个WebService Of ArrayList !</multiRef>
</multiRef>
</soapenv:Body>
</soapenv:Envelope>