我自己写的一个服务端需要的参数是一个对象数组 比如
public String getAge(Student[] ss ) {
return ss[0].getAge();
}
这种形式的,
但是在客户端调用的时候 服务端接收到的 ss 对象数组的长度都为1,里面的对象的值都为null,哪位
大神指导一下新人啊
**下面是客户端调用代码**
public static void main(String [] args) throws ServiceException, MalformedURLException, RemoteException{
String nameSpace="http://impl.webservice";
String method="getAge";
Service service = new Service();
Call call=(Call)service.createCall();
call.setTargetEndpointAddress(new java.net.URL("http://localhost:8070/TEST/services/testMyService?wsdl"));
call.setUseSOAPAction(true);
Student[] ss=new Student[2];
Student s0=new Student();
s0.setAge("123");
s0.setName("57");
ss[0]=s0;
Student s1=new Student();
s1.setAge("123");
s1.setName("213");
ss[1]=s1;
QName qn =new QName(nameSpace,method);
call.setOperationName(qn);
call.registerTypeMapping(Student.class, qn,
new org.apache.axis.encoding.ser.BeanSerializerFactory(Student.class, qn),
new org.apache.axis.encoding.ser.BeanDeserializerFactory(Student.class, qn));
String ret = (String) call.invoke(new Object[] {ss});
System.out.println(ret);
}
真是晕死,困扰了好几天的问题上午刚问出来下午就找到问题了,这是不是也是小黄鸭 调试法的一种呢 哈哈
call.invoke 的参数本来就是数组,就不用再在数组里面加数组了,好蛋疼的问题,我这么粗心是不是不能在干程序员啦~~
代码如下:
public static void main(String [] args) throws ServiceException, MalformedURLException, RemoteException{
Logger log=Logger.getLogger(Client.class);
String nameSpace="http://impl.webservice";
String method="getAge";
Service service = new Service();
Call call=(Call)service.createCall();
call.setTargetEndpointAddress(new java.net.URL("http://localhost:8070/TEST/services/testMyService?wsdl"));
call.setUseSOAPAction(true);
Object[] ss=new Student[2];
Student s0=new Student();
s0.setAge("123");
s0.setName("57");
ss[0]=s0;
Student s1=new Student();
s1.setAge("123");
s1.setName("213");
ss[1]=s1;
QName qn =new QName(nameSpace,method);
call.setOperationName(qn);
call.registerTypeMapping(Student.class, qn,
new org.apache.axis.encoding.ser.BeanSerializerFactory(Student.class, qn),
new org.apache.axis.encoding.ser.BeanDeserializerFactory(Student.class, qn));
for(int i=0;i<ss.length;i++){
call.addParameter(qn, XMLType.SOAP_ARRAY, ParameterMode.IN);
}
String ret = (String) call.invoke(ss);
log.info(ret);
System.out.println(ret);
}