2011-11-01 103 views
1

這是調用服務器中的函數執行某些任務的函數。但我必須傳入一個ArrayList和一個String值。我無法將ArrayList傳遞到服務器。誰能告訴我我該怎麼辦?將自定義對象的ArrayList傳遞給kSOAP函數

public void findLocation(ArrayList<APData> apdatalist, String profilename){ 
    SoapObject request = new SoapObject(NAMESPACE, "FindLocation"); 

    PropertyInfo quotesProperty = new PropertyInfo(); 
    quotesProperty.setName("profileName"); 
    quotesProperty.setValue(profilename); 
    quotesProperty.setType(String.class); 
    request.addProperty(quotesProperty); 

    request.addProperty("AP_List", APData.class); 

    envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11); 
    envelope.dotNet = true; 
    envelope.setOutputSoapObject(request); 

    HttpTransportSE httpRequest = new HttpTransportSE(URL); 
    httpRequest.debug = true; 
    String result = ""; 

    try 
    { 
     httpRequest.call(SOAP_ACTION, envelope); 
     Log.e("Request",httpRequest.requestDump.toString()); 

     SoapPrimitive response = (SoapPrimitive)envelope.getResponse(); 
     Log.e("Response",httpRequest.responseDump.toString()); 

     result = response.toString(); 
     if(result == null){ 
      Log.e("AndroidRuntime", "No location result is return!"); 
     } 
    } 
    catch(Exception e) 
    { 
     e.printStackTrace(); 
    } 
    //return temp; 
} 
+0

工作,你有沒有找到一個答案?我也有完全一樣的問題。 – Bashorings

+0

對不起...還沒有找到解決方案。 – user918197

回答

1

我發現了一個可能的解決方案。我修改了SoapSerializationEnvelope類來處理ArrayList。 我修改的方法 public void writeObjectBody(XmlSerializer writer, KvmSerializable obj)

public void writeObjectBody(XmlSerializer writer, KvmSerializable obj) throws IOException 
{ 
    // Added this code for parsing attributes of KvmSerializable objects 

    int cnt = obj.getPropertyCount(); 
    PropertyInfo info = new PropertyInfo(); 
    for (int i = 0; i < cnt; i++) 
    { 
     Object prop = obj.getProperty(i); 
     if(!(prop instanceof SoapObject)) { 
      // prop is a PropertyInfo 
      obj.getPropertyInfo(i, properties, info); 

      // Added this code to parse ArrayList objects in requests 
      if(prop instanceof ArrayList<?>){ 
       ArrayList<?> values = (ArrayList<?>)prop; 
       for(Object o : values){ 
        writer.startTag(info.namespace, info.name); 
        writeProperty(writer, o, info); 
        writer.endTag(info.namespace, info.name); 
       } 
      }else if ((info.flags & PropertyInfo.TRANSIENT) == 0) 
      { 
       writer.startTag(info.namespace, info.name); 
       writeProperty(writer, obj.getProperty(i), info); 
       writer.endTag(info.namespace, info.name); 
      } 
     } else { 
      // prop is a SoapObject 
      SoapObject nestedSoap = (SoapObject)prop; 
      writer.startTag(nestedSoap.getNamespace(), nestedSoap.getName()); 
      writeObjectBody(writer, nestedSoap); 
      writer.endTag(nestedSoap.getNamespace(), nestedSoap.getName()); 
     } 
    } 
} 

這似乎爲我

+0

如何以及在哪裏調用此方法 – Umair