将复杂对象添加到SOAP响应

时间:2013-10-26 13:45:36

标签: object response android-ksoap2 serializable envelope

我将复杂的对象发送到Request,如: this 现在我想从Response中获取复杂的对象。 以下是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()方法定义为blew:

@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;        

}

我创建了像这样的Errors类:

   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 linkthis envelope.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是'真的'?!如果是错的,那么当前的答案是什么。 如果有人帮助我,我将不胜感激。 提前致谢

对不起我的英语。

0 个答案:

没有答案