I have a web service that returns an ArrayList that is working fine when tested when invoking the service. However, when I call the function from aremote app I get NULL objects.
Wb Service function.
Code:
public ArrayList GetTicketsForOffline()
{
// Connect to DB
SqlConnection connStr = new SqlConnection(System.Configuration.ConfigurationManager.AppSettings["idaura"]);
// Call sproc
string procString = "pr_ticket_all_get";
SqlCommand cmd = connStr.CreateCommand();
cmd.CommandText = procString;
cmd.CommandType = CommandType.StoredProcedure;
connStr.Open();
// run sproc
cmd.ExecuteNonQuery();
SqlDataAdapter dataAdapter = new SqlDataAdapter();
dataAdapter.SelectCommand = cmd;
// Setup Dataset
DataSet dsTickets = new DataSet();
// Loop thru and store data into Dataset
dataAdapter.Fill(dsTickets, "Tickets");
// display the rows in the Tickets DataTable
ArrayList arrTickets = new ArrayList();
DataTable tickets = dsTickets.Tables["Tickets"];
foreach (DataRow ticket in tickets.Rows)
{
TicketVO ticketsObj = new TicketVO();
ticketsObj.TicketID = (int)ticket["ticket_id"];
ticketsObj.EventID = (int)ticket["event_id"];
ticketsObj.OrderID = (int)ticket["order_id"];
ticketsObj.StatusID = (int)ticket["ticket_status_id"];
ticketsObj.TypeID = (int)ticket["ticket_type_id"];
ticketsObj.IPAddress = (string)ticket["ip_address"];
ticketsObj.SaleDate = (DateTime)ticket["issue_date"];
ticketsObj.ScanDate = DateTime.Now;
arrTickets.Add(ticketsObj);
}
// Close Connection
connStr.Close();
return arrTickets;
}
Call to function which return NULL objects
Code:
ArrayList arrTickets = new ArrayList(service.GetTicketsForOffline());
Just change the service method signature to return an array of objects.
Code:
public TicketVO[ ] GetTicketsForOffline()
{
// Connect to DB
using( SqlConnection connStr = new SqlConnection(System.Configuration.ConfigurationManager.AppSettings["idaura"]) )
{
// Call sproc
using( SqlCommand cmd = connStr.CreateCommand() )
{
cmd.CommandText = "pr_ticket_all_get";
cmd.CommandType = CommandType.StoredProcedure;
connStr.Open();
// run sproc
SqlDataReader reader = cmd.ExecuteReader();
// Loop through records and add them to the list
List<TicketVO > _ticketList = new List< TicketVO >( );
while ( reader.Read( ) )
{
TicketVO ticket = new TicketVO();
ticket.TicketID = (int)reader["ticket_id"];
ticket.EventID = (int)reader["event_id"];
ticket.OrderID = (int)reader["order_id"];
ticket.StatusID = (int)reader["ticket_status_id"];
ticket.TypeID = (int)reader["ticket_type_id"];
ticket.IPAddress = (string)reader["ip_address"];
ticket.SaleDate = (DateTime)reader["issue_date"];
ticket.ScanDate = DateTime.Now;
ticketList.Add(ticketsObj);
}
}
return ticketList.ToArray( );
}
}
I've replaced the ArrayList to use the generic List collection. Also, I'm using the using block to close the sql connection and sql command objects.
Finally I'm using the SqlDataReader class to directly extract the records.
Last edited by Arjay; November 20th, 2009 at 01:34 PM.
Cannot implicitly convert type 'object[]' to 'URATicketScanMobile.com.smartonline.dev.urassociation.neweventtickets.TicketVO[]'. An explicit conversion exists (are you missing a cast?)
Bookmarks