2012-07-23 90 views
1

我想通過android應用程序中的soap服務調用發送一個複雜的對象。我得到一個很奇怪的錯誤。Android ksoap2發送複雜對象

,我試圖序列和發送(以及包括它的一個)的類如下:

public class TSavedMessage extends BaseObject{ 
public static Class TSAVEDMESSAGE_CLASS = new TSavedMessage().getClass(); 
protected String sToken; 
protected String dateDeferredDelivery; 
protected int idDepartment; 
protected boolean bDraft; 
protected String txtRelationsType; 
protected String txtRelatedIds; 
protected int idForwardOf; 
protected int idReplyOf; 
protected String numPriority; 
protected boolean bReadReceipt; 
protected boolean bDeliveryReport; 
protected String txtKeywords; 
protected int numTimeOffset; 
protected String txtTimeZone; 
protected String txtSubject; 
protected String txtBody; 
protected TRecipient[] recipients; 

public TSavedMessage() { 
} 

public TSavedMessage(String sToken, String dateDeferredDelivery, int idDepartment, boolean bDraft, String txtRelationsType, String txtRelatedIds, int idForwardOf, int idReplyOf, String numPriority, boolean bReadReceipt, boolean bDeliveryReport, String txtKeywords, int numTimeOffset, String txtTimeZone, String txtSubject, String txtBody, TRecipient[] recipients, int[] vesselRelations) { 
    this.sToken = sToken; 
    this.dateDeferredDelivery = dateDeferredDelivery; 
    this.idDepartment = idDepartment; 
    this.bDraft = bDraft; 
    this.txtRelationsType = txtRelationsType; 
    this.txtRelatedIds = txtRelatedIds; 
    this.idForwardOf = idForwardOf; 
    this.idReplyOf = idReplyOf; 
    this.numPriority = numPriority; 
    this.bReadReceipt = bReadReceipt; 
    this.bDeliveryReport = bDeliveryReport; 
    this.txtKeywords = txtKeywords; 
    this.numTimeOffset = numTimeOffset; 
    this.txtTimeZone = txtTimeZone; 
    this.txtSubject = txtSubject; 
    this.txtBody = txtBody; 
    this.recipients = recipients; 
} 

public String getSToken() { 
    return sToken; 
} 

public void setSToken(String sToken) { 
    this.sToken = sToken; 
} 

public String getDateDeferredDelivery() { 
    return dateDeferredDelivery; 
} 

public void setDateDeferredDelivery(String dateDeferredDelivery) { 
    this.dateDeferredDelivery = dateDeferredDelivery; 
} 

public int getIdDepartment() { 
    return idDepartment; 
} 

public void setIdDepartment(int idDepartment) { 
    this.idDepartment = idDepartment; 
} 

public boolean isBDraft() { 
    return bDraft; 
} 

public void setBDraft(boolean bDraft) { 
    this.bDraft = bDraft; 
} 

public String getTxtRelationsType() { 
    return txtRelationsType; 
} 

public void setTxtRelationsType(String txtRelationsType) { 
    this.txtRelationsType = txtRelationsType; 
} 

public String getTxtRelatedIds() { 
    return txtRelatedIds; 
} 

public void setTxtRelatedIds(String txtRelatedIds) { 
    this.txtRelatedIds = txtRelatedIds; 
} 

public int getIdForwardOf() { 
    return idForwardOf; 
} 

public void setIdForwardOf(int idForwardOf) { 
    this.idForwardOf = idForwardOf; 
} 

public int getIdReplyOf() { 
    return idReplyOf; 
} 

public void setIdReplyOf(int idReplyOf) { 
    this.idReplyOf = idReplyOf; 
} 

public String getNumPriority() { 
    return numPriority; 
} 

public void setNumPriority(String numPriority) { 
    this.numPriority = numPriority; 
} 

public boolean isBReadReceipt() { 
    return bReadReceipt; 
} 

public void setBReadReceipt(boolean bReadReceipt) { 
    this.bReadReceipt = bReadReceipt; 
} 

public boolean isBDeliveryReport() { 
    return bDeliveryReport; 
} 

public void setBDeliveryReport(boolean bDeliveryReport) { 
    this.bDeliveryReport = bDeliveryReport; 
} 

public String getTxtKeywords() { 
    return txtKeywords; 
} 

public void setTxtKeywords(String txtKeywords) { 
    this.txtKeywords = txtKeywords; 
} 

public int getNumTimeOffset() { 
    return numTimeOffset; 
} 

public void setNumTimeOffset(int numTimeOffset) { 
    this.numTimeOffset = numTimeOffset; 
} 

public String getTxtTimeZone() { 
    return txtTimeZone; 
} 

public void setTxtTimeZone(String txtTimeZone) { 
    this.txtTimeZone = txtTimeZone; 
} 

public String getTxtSubject() { 
    return txtSubject; 
} 

public void setTxtSubject(String txtSubject) { 
    this.txtSubject = txtSubject; 
} 

public String getTxtBody() { 
    return txtBody; 
} 

public void setTxtBody(String txtBody) { 
    this.txtBody = txtBody; 
} 

public TRecipient[] getRecipients() { 
    return recipients; 
} 

public void setRecipients(TRecipient[] recipients) { 
    this.recipients = recipients; 
} 

public Object getProperty(int index) { 
    switch (index) { 
    case 0: 
     return sToken; 
    case 1: 
     return dateDeferredDelivery; 
    case 2: 
     Integer iDepartment = new Integer(idDepartment); 
     return iDepartment; 
    case 3: 
     Boolean isDraft = new Boolean(bDraft); 
     return isDraft; 
    case 4: 
     return txtRelationsType; 
    case 5: 
     return txtRelatedIds; 
    case 6: 
     Integer iForwardOf = new Integer(idForwardOf); 
     return iForwardOf; 
    case 7: 
     Integer iReplyOf = new Integer(idReplyOf); 
     return iReplyOf; 
    case 8: 
     return numPriority; 
    case 9: 
     Boolean isReadReceipt = new Boolean(bReadReceipt); 
     return isReadReceipt; 
    case 10: 
     Boolean isDeliveryReport = new Boolean(bDeliveryReport); 
     return isDeliveryReport; 
    case 11: 
     return txtKeywords; 
    case 12: 
     Integer iTimeOffset = new Integer(numTimeOffset); 
     return iTimeOffset; 
    case 14: 
     return txtTimeZone; 
    case 15: 
     return txtSubject; 
    case 16: 
     return txtBody; 
    case 17: 
     return recipients; // complex type 
    default: 
     return null; 
    } 
} 

public int getPropertyCount() { 
    return 18; 
} 

public void getPropertyInfo(int index, Hashtable properties, PropertyInfo info) { 
    switch (index) { 
    case 0: 
     info.type = PropertyInfo.STRING_CLASS; 
     info.name = "sToken"; 
     break; 
    case 1: 
     info.type = PropertyInfo.STRING_CLASS; 
     info.name = "dateDeferredDelivery"; 
     break; 
    case 2: 
     info.type = PropertyInfo.INTEGER_CLASS; 
     info.name = "idDepartment"; 
     break; 
    case 3: 
     info.type = PropertyInfo.BOOLEAN_CLASS; 
     info.name = "bDraft"; 
     break; 
    case 4: 
     info.type = PropertyInfo.STRING_CLASS; 
     info.name = "txtRelationsType"; 
     break; 
    case 5: 
     info.type = PropertyInfo.STRING_CLASS; 
     info.name = "txtRelatedIds"; 
     break; 
    case 6: 
     info.type = PropertyInfo.INTEGER_CLASS; 
     info.name = "idForwardOf"; 
     break; 
    case 7: 
     info.type = PropertyInfo.INTEGER_CLASS; 
     info.name = "idReplyOf"; 
     break; 
    case 8: 
     info.type = PropertyInfo.STRING_CLASS; 
     info.name = "numPriority"; 
     break; 
    case 9: 
     info.type = PropertyInfo.BOOLEAN_CLASS; 
     info.name = "bReadReceipt"; 
     break; 
    case 10: 
     info.type = PropertyInfo.BOOLEAN_CLASS; 
     info.name = "bDeliveryReport"; 
     break; 
    case 11: 
     info.type = PropertyInfo.STRING_CLASS; 
     info.name = "txtKeywords"; 
     break; 
    case 12: 
     info.type = PropertyInfo.INTEGER_CLASS; 
     info.name = "numTimeOffset"; 
     break; 
    case 14: 
     info.type = PropertyInfo.STRING_CLASS; 
     info.name = "txtTimeZone"; 
     break; 
    case 15: 
     info.type = PropertyInfo.STRING_CLASS; 
     info.name = "txtSubject"; 
     break; 
    case 16: 
     info.type = PropertyInfo.STRING_CLASS; 
     info.name = "txtBody"; 
     break; 
    case 17: 
     info.type = PropertyInfo.VECTOR_CLASS; 
     info.name = "recipients"; // complex type 
     break; 
    default: 
     break; 
    }  
} 

public void setProperty(int index, Object value) { 
    switch (index) { 
    case 0: 
     sToken = value.toString(); 
     break; 
    case 1: 
     dateDeferredDelivery = value.toString(); 
     break; 
    case 2: 
     idDepartment = Integer.parseInt(value.toString()); 
     break; 
    case 3: 
     if(value.toString().equalsIgnoreCase("false")) bDraft = false; 
     else bDraft = true; 
     break; 
    case 4: 
     txtRelationsType = value.toString(); 
     break; 
    case 5: 
     txtRelatedIds = value.toString(); 
     break; 
    case 6: 
     idForwardOf = Integer.parseInt(value.toString()); 
     break; 
    case 7: 
     idReplyOf = Integer.parseInt(value.toString()); 
     break; 
    case 8: 
     numPriority = value.toString(); 
     break; 
    case 9: 
     if(value.toString().equalsIgnoreCase("false")) bReadReceipt = false; 
     else bReadReceipt = true; 
     break; 
    case 10: 
     if(value.toString().equalsIgnoreCase("false")) bDeliveryReport = false; 
     else bDeliveryReport = true; 
     break; 
    case 11: 
     txtKeywords = value.toString(); 
     break; 
    case 12: 
     numTimeOffset = Integer.parseInt(value.toString()); 
     break; 
    case 14: 
     txtTimeZone = value.toString(); 
     break; 
    case 15: 
     txtSubject = value.toString(); 
     break; 
    case 16: 
     txtBody = value.toString(); 
     break; 
    case 17: 
     recipients = (TRecipient[]) value; // complex type 
     break; 
    default: 
     break; 
    } 
} 

}

public class TRecipient extends BaseObject{ 
public static Class TRECIPIENT_CLASS = new TRecipient().getClass(); 
protected int idRecipient; 
protected String txtRealAddress; 
protected String Visibility; 

public TRecipient() { 
} 

public TRecipient(int idRecipient, String txtRealAddress, String visibility) { 
    this.idRecipient = idRecipient; 
    this.txtRealAddress = txtRealAddress; 
    this.Visibility = visibility; 
} 

public int getIdRecipient() { 
    return idRecipient; 
} 

public void setIdRecipient(int idRecipient) { 
    this.idRecipient = idRecipient; 
} 

public String getTxtRealAddress() { 
    return txtRealAddress; 
} 

public void setTxtRealAddress(String txtRealAddress) { 
    this.txtRealAddress = txtRealAddress; 
} 

public String getVisibility() { 
    return Visibility; 
} 

public void setVisibility(String visibility) { 
    this.Visibility = visibility; 
} 

public Object getProperty(int index) { 
    switch (index) { 
    case 0: 
     Integer iRecipient = new Integer(idRecipient); 
     return iRecipient; 
    case 1: 
     return txtRealAddress; 
    case 2: 
     return Visibility; 
    default: 
     return null; 
    } 
} 

public int getPropertyCount() { 
    return 3; 
} 

public void getPropertyInfo(int index, Hashtable properties, PropertyInfo info) { 
    switch (index) { 
    case 0: 
     info.type = PropertyInfo.INTEGER_CLASS; 
     info.name = "idRecipient"; 
     break; 
    case 1: 
     info.type = PropertyInfo.STRING_CLASS; 
     info.name = "txtRealAddress"; 
     break; 
    case 2: 
     info.type = PropertyInfo.STRING_CLASS; 
     info.name = "Visibility"; 
     break; 
    default: 
     break; 
    } 
} 

public void setProperty(int index, Object value) { 
    switch (index) { 
    case 0: 
     idRecipient = Integer.parseInt(value.toString()); 
     break; 
    case 1: 
     txtRealAddress = value.toString(); 
     break; 
    case 2: 
     Visibility = value.toString(); 
     break; 
    default: 
     break; 
    } 
} 

}

的方法發送請求如下:

  TSavedMessage msgTemp = new TSavedMessage(); 
     msgTemp.setSToken(LoginActivity.sToken); 
     DateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss"); 
     Date date = new Date(); 
     msgTemp.setDateDeferredDelivery(dateFormat.format(date)); 
     msgTemp.setIdDepartment(datasource.getDepartmentID(departmentString)); 
     msgTemp.setBDraft(false); 
     msgTemp.setTxtRelationsType(""); 
     msgTemp.setTxtRelatedIds(""); 
     msgTemp.setIdForwardOf(params[1]); 
     msgTemp.setIdReplyOf(params[2]); 
     msgTemp.setNumPriority("Normal"); 
     msgTemp.setBReadReceipt(false); 
     msgTemp.setBDeliveryReport(false); 
     msgTemp.setTxtKeywords(keywords.getText().toString()); 
     msgTemp.setNumTimeOffset(0); 
     msgTemp.setTxtTimeZone("0"); 
     msgTemp.setTxtSubject(subject.getText().toString()); 
     msgTemp.setTxtBody(body.getText().toString()); 
     TRecipient[] recarrayTemp = new TRecipient[1]; 
     recarrayTemp[0] = new TRecipient(0, "[email protected]", "To"); 
     msgTemp.setRecipients(recarrayTemp); 

     SoapObject recipients = new SoapObject(LoginActivity.NAMESPACE, "Recipients"); 
     SoapObject recarray[] = new SoapObject[1]; 
     for (int i = 0; i < 1; i++){ 
      recarray[i] = new SoapObject(BaseObject.NAMESPACE, "TRecipient"); 
      recarray[i].addProperty("idRecipient", Integer.toString(0)); 
      recarray[i].addProperty("txtRealAddress", "[email protected]"); 
      recarray[i].addProperty("Visibility", "To"); 
      recipients.addProperty("TRecipient", recarray[i]); 
     } 

     SoapObject msg = new SoapObject(BaseObject.NAMESPACE, "MessageToSend"); 
     msg.addProperty("sToken", LoginActivity.sToken); 
     msg.addProperty("dateDeferredDelivery", msgTemp.getDateDeferredDelivery()); 
     msg.addProperty("idDepartment", Integer.toString(msgTemp.getIdDepartment())); 
     msg.addProperty("bDraft", "false"); 
     msg.addProperty("txtRelationsType", Integer.toString(0)); 
     msg.addProperty("txtRelatedIds", Integer.toString(0)); 
     msg.addProperty("idForwardOf", Integer.toString(0)); 
     msg.addProperty("idReplyOf", Integer.toString(0)); 
     msg.addProperty("numPriority", msgTemp.getNumPriority()); 
     msg.addProperty("bReadReceipt", "false"); 
     msg.addProperty("bDeliveryReport", "false");   
     msg.addProperty("txtKeywords", msgTemp.getTxtKeywords()); 
     msg.addProperty("numTimeOffset", msgTemp.getNumTimeOffset()); 
     msg.addProperty("txtTimeZone", msgTemp.getTxtTimeZone()); 
     msg.addProperty("txtSubject", msgTemp.getTxtSubject()); 
     msg.addProperty("txtBody", msgTemp.getTxtBody()); 
     msg.addProperty("Recipients", recipients); 

     SoapObject rpc = new SoapObject(BaseObject.NAMESPACE, METHOD_NAME);  
     rpc.addProperty("sToken", LoginActivity.sToken); 
     rpc.addProperty("MessageToSend", msg); 

     SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11); 
     envelope.bodyOut = rpc; 
     envelope.dotNet = true; 
     envelope.encodingStyle = SoapSerializationEnvelope.XSD; 

     try { 
      HttpTransportSE androidHttpTransport = new HttpTransportSE(LoginActivity.URL); 
      androidHttpTransport.debug = true; 
      androidHttpTransport.setXmlVersionTag("<?xml version=\"1.0\" encoding=\"UTF-8\"?>"); 
      androidHttpTransport.call(SOAP_ACTION, envelope); 
      System.out.println("=== " + envelope.getResponse().toString());     
     } 
     catch(XmlPullParserException e) { 
      e.printStackTrace(); 
     } 
     catch(IOException e) { 
      e.printStackTrace(); 
     } 

最後,我得到的錯誤是這個:

SoapFault - faultcode: 'EConvertError' faultstring: '''[email protected]'' is not a valid integer value' 

faultactor:「空」的細節:空

這是很不幸的是,錯誤指向我無處。我無法理解爲什麼正在嘗試將這3個字段作爲整數傳遞。此外,讓我感到困擾的是,在左側有一個三重報價而在右側有一個雙重報價。

任何想法都可能證明是非常有價值的。提前致謝。

此外,此代碼生成並嘗試發送的soap對象似乎完全正常。它是這樣的:

MobSaveMessage{ 
sToken=MOB-2704FB8FFBC946469408A3BEE90CA163; 
MessageToSend=MessageToSend{ 
    sToken=MOB-2704FB8FFBC946469408A3BEE90CA163; 
    dateDeferredDelivery=2012/07/25 13:30:36; 
    idDepartment=18; 
    bDraft=false; 
    txtRelationsType=0; 
    txtRelatedIds=0; 
    idForwardOf=0; 
    idReplyOf=0; 
    numPriority=Normal; 
    bReadReceipt=false; 
    bDeliveryReport=false; 
    txtKeywords=key; 
    numTimeOffset=0; 
    txtTimeZone=0; 
    txtSubject=sub; 
    txtBody=mail; 
    Recipients=Recipients{ 
     TRecipient=TRecipient{ 
      idRecipient=0; 
      [email protected]; 
      Visibility=To; 
     }; 
    }; 
}; 

}

回答

2

畢竟事實證明,我們與規格一起發送給我們的WSDL文件的版本錯誤。如果我讓任何人陷入困境,我真的很抱歉。不是我的錯。我只是在迴應,以防有人遇到問題。