KSOAP ANDROID - Recevoir struct de C # Web Service
-
22-10-2019 - |
Question
Je construis une application Android qui se connecte à mon ASP.NET Web Service.
Je l'ai déjà créé la connexion à l'aide KSOAP et je réussis à exécuter des méthodes qui renvoie des chaînes et int.
J'utilise SoapPrimitive recevoir ces méthodes:
SoapPrimitive resultString = (SoapPrimitive)soapEnvelope.getResponse();
Le problème est quand j'ai une méthode qui renvoie la struct de suivi -. Tableau
Comment puis-je recevoir?
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();
}
}
}
La solution
Je pense que ce lien vous aidera: service Web qui renvoie un tableau d'objets avec KSOAP
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow