2011-09-04 4 views
0

저는 ASP.NET 웹 서비스에 연결할 Android APP를 구축하고 있습니다.CSOAP ANDROID - C# 웹 서비스에서 구조체 받기

나는 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(); 
      } 
     } 


    } 

답변

0

나는이 링크가 도움이 될 것입니다 생각 : Web Service That Returns An Array of Objects With KSOAP

+0

감사 Gravecard! 내 프로젝트에 삽입 된이 페이지의 모든 코드를 복사했으며 프로젝트에서 Struct을 만들어야합니다. java가 Structs를 가지고 있지 않다는 것을 기억하기 때문에 클래스를 만들었습니다. – Michel