2013-08-19 99 views
2

嗨,所以我一直在搜索谷歌一段時間,但似乎不能有一個堅實的例子。過去幾天我一直在使用webservice和android一起工作,我可以成功地從android傳遞參數,並用ksoap將其消耗完畢,沒有任何問題。但是現在我需要將一個數組傳遞給一個web服務。所以,我的繼承人簡單的Web服務:傳遞字符串數組到C#的Web服務(Android Ksoap2)

[WebMethod] 
public string Sample(string[] logs) 
{ 
    return array[0]; 
} 

這是我需要生成XML:

<?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> 
    <Sample xmlns="http://MTKAndroidService.org/"> 
     <array> 
     <string>string</string> 
     <string>string</string> 
     </array> 
    </Sample> 
    </soap:Body> 
</soap:Envelope> 

我一直堅持這一有一段時間了,希望有人能幫助我。

+1

怎麼樣正好路過一個逗號分隔的字符串,然後使用'String []數組= String.Split (「,」,輸入);' – Jonesopolis

+0

感謝您的回覆。是的,我已經冒險進入這個選項,但如果我這樣做的話,弦會太長。我們在這裏談論高達100個字符串值,所以我不認爲最好使用這種技術 – TheProvost

回答

4

終於得到它....對於那些誰是停留在此也生病後我的回答

public String Sample() 
    { 
     String SOAP_ACTION = "http://MTKAndroidService.org/Sample"; 
     String METHOD_NAME = "Sample"; 
//  URL = "http://10.0.2.2:49923/Service1.asmx"; // to be adjusted to the URL above once this code is added into WebService; 
     String IP_LIST=""; 
     SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME); 
     List<String> logs = new ArrayList<String>(); 
     logs.add("hello"); 
     logs.add("world"); 
     SoapObject soapLogs = new SoapObject(NAMESPACE, "logs"); 
     for (String i : logs){ 
      soapLogs.addProperty("string", i); 
     } 
     request.addSoapObject(soapLogs); 

     SoapSerializationEnvelope IPenvelope = new SoapSerializationEnvelope(SoapEnvelope.VER11); 
     IPenvelope.dotNet = true; 
     IPenvelope.setOutputSoapObject(request); 
     HttpTransportSE androidHttpTransport = new HttpTransportSE(URL); 

      try 
      { 
       androidHttpTransport.call(SOAP_ACTION, IPenvelope); 
       SoapPrimitive response = (SoapPrimitive)IPenvelope.getResponse(); 
       Log.i("myApp", response.toString()); 
       IP_LIST= response.toString(); 
      } 
      catch (Exception e) 
      { 
       e.printStackTrace(); 
      } 
      return IP_LIST; 
    } 
+0

@TheProvots:請。請參考此鏈接[http://stackoverflow.com/questions/19198017/pass-arraylist-data-into-soap-web-service-in-android] http://stackoverflow.com/questions/19198017/pass-arraylist-數據到肥皂web服務在Android)你有什麼想法我怎麼能發送這種類型的數據肥皂服務 –

+0

嗨,很抱歉,我登錄後很長一段時間...無論如何,你仍然有問題有了這個?我似乎無法訪問您的頁面 – TheProvost

+0

:引用鏈接[http://stackoverflow.com/questions/19353244/issue-in-passing-json-format-in-soap-service-android](http://stackoverflow.com/questions/19353244/issue-in-passing-json-format-in-soap-service-android)我該如何傳遞這些數據? –

相關問題