服务器端定义:
public class TestService {
public String getStr(String input) {
return "Input string:"+input;
}
public Bean getBean(Bean bean) {
System.out.println("Bean Name:"+bean.getName());
bean.setName(bean.getName()+"OK");
Bean bb = new Bean();
bb.setName("haha");
return bb;
}
public Bean[] getBeans(String str) {
Bean[] rets = new Bean[2];
Bean bean1 = new Bean();
bean1.setName("name 1");
Bean bean2 = new Bean();
bean2.setName("name 2");
rets[0] = bean1;
rets[1] = bean2;
return rets;
}
}
server-config.wsdd中的配置:
自定义类
<typeMapping deserializer="org.apache.axis.encoding.ser.BeanDeserializerFactory" encodingStyle="" qname="ns6:Bean" serializer="org.apache.axis.encoding.ser.BeanSerializerFactory" type="java:com.test.bean.Bean" xmlns:ns6="http://bean.test.com"/>
数组
<typeMapping xmlns:ns7="http://bean.test.com" qname="ns7:ArrayOf_Bean" type="java:com.test.bean.Bean[]" serializer="org.apache.axis.encoding.ser.ArraySerializerFactory" deserializer="org.apache.axis.encoding.ser.ArrayDeserializerFactory" encodingStyle="" />
客户端调用:
String endpoint = "http://localhost:8081/axistest/services/TestService";
Service service3 = new Service();
Call call3 = (Call) service3.createCall();
QName qn3 = new QName("http://bean.test.com","ArrayOf_Bean");
//注册 bean
call3.registerTypeMapping(Bean.class,qn,new BeanSerializerFactory(Bean.class, qn),new BeanDeserializerFactory(Bean.class, qn));
call3.registerTypeMapping(Bean[].class,qn3,new BeanSerializerFactory(Bean[].class, qn3),new BeanDeserializerFactory(Bean[].class, qn3));
call3.setTargetEndpointAddress(new java.net.URL(endpoint));
call3.setOperationName(new QName("getBeans"));
call3.addParameter("arg1", qn, ParameterMode.IN);
call3.setReturnType(qn,Bean.class);
java.util.ArrayList ret3 = (java.util.ArrayList) call3.invoke(new Object[] {"test--"});
System.out.println((ret3==null)?"null":(""+ret3.size()));