我将复杂对象发送到请求,例如: 现在 我想从响应中获取复杂对象。以下是一个示例 SOAP 1.1 响应:
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<CommitReceiptionAgentResponse xmlns="http://mywebService.ir/">
<CommitReceiptionAgentResult Exc="string">
<Errors>
<string>string</string>
<string>string</string>
</Errors>
<CST>dateTime</CST>
</CommitReceiptionAgentResult>
</CommitReceiptionAgentResponse>
</soap:Body>
</soap:Envelope>
我创建了 CommitReceiptionAgentResponse 类:
public class CommitReceiptionAgentResponse implements KvmSerializable {
@Element(name = "CommitReceiptionAgentResult")
CommitReceiptionAgentResult commitReceiptionAgentResult;
.
.
.
}
我也创建了 CommitReceiptionAgentResult 类:
public class CommitReceiptionAgentResult extends Vector<String> implements KvmSerializable {
@ElementList(name = "Errors")
public Errors errors;
@Attribute(name = "Exc", required = false)
public String InternalServiceException;
@Element(name = "CST", required = false)
public Date CommitStartTime;
.
.
.
}
CommitReceiptionAgentResult 类的 getProperty() 方法定义为自爆:
@Override
public Object getProperty(int arg0) {
switch (arg0) {
case 0:
Errors errorList = getErrors();
SoapObject erlistObject = new SoapObject(
ServiceUtil.WSDL_TARGET_NAMESPACE, "errorList");
try{
if (errorList.size() > 0) {
for (String error : errorList) {
SoapObject erObject = new SoapObject(
ServiceUtil.WSDL_TARGET_NAMESPACE, "Errors");
PropertyInfo info = new PropertyInfo();
errorList.getPropertyInfo(0, null, info);
erObject.addProperty(info.name,
errorList.getProperty(0));
erlistObject.addSoapObject(erObject);
}
}
}catch (Exception e) {
}
return erlistObject;
case 1:
return getInternalServiceException();
case 2:
return getCommitStartTime();
}
return null;
}
@Element(name = "CST", required = false)
public Date CommitStartTime;
}
我创建了这样的错误类:
public class Errors extends Vector<String> implements KvmSerializable{
@Override
public Object getProperty(int arg0) {
return this.get(arg0);
}
@Override
public int getPropertyCount() {
return 1;
}
@Override
public void getPropertyInfo(int arg0, Hashtable arg1, PropertyInfo arg2) {
arg2.name = "string";
arg2.type = PropertyInfo.STRING_CLASS;
}
@Override
public void setProperty(int arg0, Object arg1) {
this.add(arg1.toString());
}
}
当我根据 此链接 和 this定义肥皂对象和信封时 ,信封.getResponse() 为空:
final SoapObject response1 = new SoapObject(WSDL_TARGET_NAMESPACE,
"CommitReceiptionAgentResponse");
response1.addProperty("CommitReceiptionAgentResult",
new CommitReceiptionAgentResult());
final SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(
SoapEnvelope.VER11);
envelope.bodyOut = request;
envelope.setOutputSoapObject(response1);
envelope.addMapping(WSDL_TARGET_NAMESPACE,
"CommitReceiptionAgentResponse",
new CommitReceiptionAgentResponse().getClass());
envelope.addMapping(WSDL_TARGET_NAMESPACE,
"CommitReceiptionAgentResult",
new CommitReceiptionAgentResult().getClass());
envelope.addMapping(WSDL_TARGET_NAMESPACE, "Errors",
new Errors().getClass());
HttpTransportSE httpTransport1 = new HttpTransportSE(SOAP_ADDRESS);
try {
httpTransport1.debug = true;
httpTransport1.setXmlVersionTag("<?xml version=\"1.0\" encoding=\"utf-8\"?>");
httpTransport1.call(SOAP_ACTION, envelope); // in/out
SoapObject response = (SoapObject) soapEnvelope.getResponse();
}catch(exception){}
我搜索了很多,但找不到问题。我想知道我的类和 addMAppings 的实现是“真的”吗?!如果是错误的,正确的答案是什么。如果有人帮助我,我将不胜感激。提前致谢
对不起我的英语。