我自己寫的一個服務端需要的參數是一個對象數組 比如
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);
}