我正在构建一个将连接到我的ASP.NET Web服务的Android APP。
我已经使用KSOAP创建了连接,并且我成功执行了返回字符串和int的方法。
我正在使用SoapPrimitive来接收这些方法:
SoapPrimitive resultString = (SoapPrimitive)soapEnvelope.getResponse();
问题是当我有一个方法返回跟随struct - Array。
我怎样才能收到它?
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();
}
}
}