使用肥皂客户端响应的第一个元素。
问题来自于映射类型名称空间:没有名称空间
所以现在,我有
smr.mapTypes(Constants.NS_URI_SOAP_ENC,new QName("","student"),Student.class, null, new BeanSerializer());
smr.mapTypes(Constants.NS_URI_SOAP_ENC,new QName("","matricule"),Integer.class, null, new IntDeserializer());
smr.mapTypes(Constants.NS_URI_SOAP_ENC,new QName("","name"),Integer.class, null, new StringDeserializer());
并且还添加
@XmlRootElement(name = "Student",namespace="http://services.tuto.java.com/")
到学生班级
<?xml version="1.0" encoding="UTF-8"?>
<S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/">
<S:Body>
<ns2:getStudentsResponse xmlns:ns2="http://services.tuto.java.com/">
<student>
<matricule>1236</matricule>
<name>student1</name>
</student>
<student>
<matricule>5678</matricule>
<name>student2</name>
</student>
</ns2:getStudentsResponse>
</S:Body>
</S:Envelope>
轴客户端:
public class AxisClient
{
public static void main(String[] args) throws Exception
{
String endPoint = "http://localhost:8080/StudentServiceImplService/StudentServiceImpl";
Service service2 = new Service();
Call call2 = (Call) service2.createCall();
call2.setTargetEndpointAddress(new java.net.URL(endPoint));
call2.setOperationName(new QName("http://services.tuto.java.com/","getStudents"));
call2.setReturnType(new QName("","student"), Student.class);
call2.setReturnType(new QName("", "student"));
call2.registerTypeMapping(Student.class, new QName("", "student"), null,new BeanDeserializerFactory(Student.class, new QName("", "student")));
List<Student> students = (List<Student>) call2.invoke(new Object[0]);
for (Student student : students)
{
System.out.println(student);
}
}
}
Giving all学生 :
Student [matricule=1236, name=student1]
Student [matricule=5678, name=student2]
axis2客户端:
public static void main(String[] args) throws Exception
{
String endPoint = "http://localhost:8080/StudentServiceImplService/StudentServiceImpl";
ServiceClient sc = new ServiceClient();
Options opts = new Options();
opts.setTo(new EndpointReference("http://localhost:8080/StudentServiceImplService/StudentServiceImpl"));
sc.setOptions(opts);
OMFactory fac = OMAbstractFactory.getOMFactory();
OMNamespace omNs = fac.createOMNamespace("http://services.tuto.java.com/","ns1");
OMElement method = fac.createOMElement("getStudents", omNs);
OMElement res = sc.sendReceive(method);
System.out.println(res);
Iterator<OMElement> it = res.getChildElements();
while(it.hasNext())
{
System.out.println(it.next());
}
}
Giving
<ns2:getStudentsResponse xmlns:ns2="http://services.tuto.java.com/"><student><matricule>1236</matricule><name>student1</name></student><student><matricule>5678</matricule><name>student2</name></student></ns2:getStudentsResponse>
<student><matricule>1236</matricule><name>student1</name></student>
<student><matricule>5678</matricule><name>student2</name></student>
但我不知道如何反序列化 omelement。
我尝试过
Student student = (Student) BeanUtil.deserialize(Student.class,res,new DefaultObjectSupplier(),null);
但给了我
Student [matricule=null, name=null]
我能怎么做 ?
留下问题:
- 不知道如何对轴做同样的事情--好的请参阅之前--/axis 2
- 'resp'(soap 客户端)包含仅第一 student