我写了一个Webservice,服务端代码如下:
public class GetList {
public ArrayList getList(String str){
System.out.println("size="+str);
int size = Integer.parseInt(str);
ArrayList list = new ArrayList();
for(int i=0;i<size;i++){
list.add("hujll");
System.out.println(list.get(i));
}
return list;
}
}
,通过tomcat服务器发布成功,
客户端代码如下:
public class TestGetList {
public static void main(String[] args) {
ArrayList returnName = null;
try {
String strName = "http://localhost:8080/axis2/services/getlist?wsdl";
Service service = new Service();
Call call = (Call) service.createCall();
QName qn = new QName("urn:getlist", "ArrayList");
call.registerTypeMapping(ArrayList.class, qn,
new BeanSerializerFactory(ArrayList.class, qn),
new BeanDeserializerFactory(ArrayList.class, qn));
call.setTargetEndpointAddress(new java.net.URL(strName));
call.setOperationName(new QName("http://list", "getList"));
call.addParameter("str", XMLType.XSD_STRING, ParameterMode.IN);
call.setReturnClass(ArrayList.class);
returnName = (ArrayList) call.invoke(new Object[] { "4" });
for (int i = 0; i < returnName.size(); i++) {
System.out.println("dd=="
+ returnName.get(i).toString());
}
} catch (ServiceException e) {
e.printStackTrace();
} catch (MalformedURLException e) {
e.printStackTrace();
} catch (RemoteException e) {
e.printStackTrace();
}
}
}
问题是:得到了集合的大小,循环打印的结果是空值及输出如下:
dd==[]
dd==[]
dd==[]
dd==[]
我查资料把返回的集合转换成数组,
String[] arr = (String[]) list.toArray();
结果报类转换异常错误。