Pregunta

Estoy creando una aplicación Android que se conectará a mi servicio web ASP.NET.

Ya creé la conexión usando KSOAP y logré ejecutar métodos que devuelven cadenas e int.

Estoy usando tan apropiado para recibir esos métodos:

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

El problema es cuando tengo un método que devuelve la estructura de seguimiento: matriz.

¿Cómo puedo recibirlo?

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


    }
¿Fue útil?

Solución

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top