我期待一个列表作为回应,但我只得到列表中预期的最后一项。我做错了什么?
wsdl部分:
<s:element name="delTrackLogsResponse">
<s:complexType>
<s:sequence>
<s:element maxOccurs="1" minOccurs="1" name="returnDocument" type="tns:Element"/>
</s:sequence>
</s:complexType>
</s:element>
<s:complexType name="Element">
<s:sequence>
<s:any processContents="lax"/>
</s:sequence>
</s:complexType>
生成 bu wsdl2java 的类:
public class DelTrackLogsResponse {
@XmlElement(required = true)
protected Element returnDocument;
//followed by getters setters
}
public class Element {
@XmlAnyElement(lax = true)
protected Object any;
//followed by getters setters
}
我对服务的调用:
response.setReturnDocument(cdCommunicationLogSession().delTrackLogs(parameters);
我编组响应对象以查看响应:
StringWriter stringWriter = new StringWriter();
JAXBContext jaxbContext = JAXBContext.newInstance(cd.communicationlog.Element.class);
Marshaller jaxbMarshaller = jaxbContext.createMarshaller();
// format the XML output
jaxbMarshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
QName qName = new QName("cd.communicationlog", "trackLogsResponse");
JAXBElement<DelTrackLogsResponse> root = new JAXBElement<DelTrackLogsResponse>(qName,DelTrackLogsResponse.class, response);
jaxbMarshaller.marshal(root, stringWriter);
String result = stringWriter.toString();
log.debug("---- result xml: " + result);
我得到的结果xml:
<ns2:trackLogsResponse xmlns:ns2="com.sample.jaxb.model" xmlns="urn:cd:communicationLog">
<returnDocument>
<element clickFlag="0" deliveryDate="2017-02-23" deliveryLabel="xyz" deliveryType="Email" firstLogDate="N/A" openFlag="0"/>
</returnDocument>
</ns2:trackLogsResponse>
当我在 SOAP UI 中运行相同的东西时,我会得到一个响应列表,例如:
<delTrackLogsResponse SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" xmlns="urn:cd:communicationLog">
<returnDocument xsi:type="ns:Element" SOAP-ENV:encodingStyle="http://xml.apache.org/xml-soap/literalxml">
<element deliveryLabel="abc" deliveryDate="2017-03-20" deliveryType="Email" firstLogDate="N/A" openFlag="0" clickFlag="0"/>
<element deliveryLabel="abc" deliveryDate="2017-03-20" deliveryType="Email" firstLogDate="N/A" openFlag="0" clickFlag="0"/>
.
.
.
.
<element deliveryLabel="xyz" deliveryDate="2017-02-23" deliveryType="Email" firstLogDate="N/A" openFlag="0" clickFlag="0"/>
<element deliveryLabel="xyz" deliveryDate="2017-02-23" deliveryType="Email" firstLogDate="N/A" openFlag="0" clickFlag="0"/>
</returnDocument>
</delTrackLogsResponse>
提前致谢 :)