-
November 20th, 2009, 09:44 AM
#1
Web Service function not returning arraylist
Hi,
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());
-
November 20th, 2009, 02:27 PM
#2
Re: Web Service function not returning arraylist
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 02:34 PM.
-
November 23rd, 2009, 10:44 AM
#3
Re: Web Service function not returning arraylist
Thanks Arjay,
Thanks for response.
The calling fucntion is the app will cause an invalid cast exception.
Code:
WebService.TicketVO[] listTickets = (WebService.TicketVO[])service.GetTicketsForOffline().ToArray();
-
November 23rd, 2009, 10:47 AM
#4
Re: Web Service function not returning arraylist
Originally Posted by lexavision
Thanks Arjay,
Thanks for response.
The calling fucntion is the app will cause an invalid cast exception.
Code:
WebService.TicketVO[] listTickets = (WebService.TicketVO[])service.GetTicketsForOffline().ToArray();
You need to rebuild the web proxy. Afterwards you should be able to call it this way:
Code:
WebService.TicketVO[] listTickets = service.GetTicketsForOffline();
-
December 2nd, 2009, 10:18 AM
#5
Re: Web Service function not returning arraylist
Thanks Arjay...
However with that approach I get a compile error:
Cannot implicitly convert type 'object[]' to 'URATicketScanMobile.com.smartonline.dev.urassociation.neweventtickets.TicketVO[]'. An explicit conversion exists (are you missing a cast?)
-
December 2nd, 2009, 12:37 PM
#6
Re: Web Service function not returning arraylist
If you've defined the web service as:
public TicketVO[ ] GetTicketsForOffline()
{
...
}
but are getting an error when calling it, check out the generated proxy code and make sure it's been generated properly.
Otherwise, have you tried to cast it?
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|