Question

I'm building a Android APP that will connect to my ASP.NET Web Service.

I already created the connection using KSOAP and I succeed to execute methods which returns strings and int.

I'm using SoapPrimitive to receive those methods:

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

The problem is when I have a method which returns the follow struct - Array.

How can I receive it?

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


    }
Was it helpful?

Solution

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top