2011-09-04 62 views
0

我正在構建一個將連接到我的ASP.NET Web服務的Android應用程序。KSOAP ANDROID - 從C#Web服務接收結構

我已經使用KSOAP創建了連接,並且我成功執行了返回字符串和int的方法。

我使用SoapPrimitive接收這些方法:

SoapPrimitive resultString = (SoapPrimitive)soapEnvelope.getResponse(); 

問題是,當我返回後續結構的方法 - 陣列。

我該如何接收?

public struct ClientData 
{ 
    public int id_note; 
    public string descricao; 
    public string timer; 
} 

[WebMethod] 
    public ClientData[] open_notes(int _id_users) 

    { 
     MySqlConnection conn = new MySqlConnection("**************************************"); 
     MySqlDataReader rdr = null; 

     int y = 0; 

     try 
     { 
      //abrir conexão 
      conn.Open(); 

      //passar conexão para command object 
      MySqlCommand cmd = conn.CreateCommand(); 

      cmd.CommandText = "SELECT id_notes, note, timer from notes WHERE id_users = '" + _id_users + "' AND note_is_active = 1 ORDER BY lastmodified DESC"; 
      rdr = cmd.ExecuteReader(); 

      ClientData[] Clients = null; 
      Clients = new ClientData[30]; 


      if (rdr.HasRows) 
      { 
       while (rdr.Read()) 
       { 
        Clients[y].id_note = int.Parse(rdr[0].ToString()); 
        Clients[y].descricao = rdr[1].ToString(); 
        Clients[y].timer = rdr[2].ToString(); 
        y = y + 1; 


       } 


       Array.Resize(ref Clients, y); 
       rdr.Close(); 


      } 
      else 
      { 
       Clients[0].id_note = 0; 
       Array.Resize(ref Clients, 1); 
      } 

      return Clients; 
     } 

     finally 
     { 
      // close the reader 
      if (rdr != null) 
      { 
       rdr.Close(); 
      } 

      // 5. Close the connection 
      if (conn != null) 
      { 
       conn.Close(); 
      } 
     } 


    } 

回答