473,320 Members | 1,845 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Web Service Data Conversion Problem


In a web service I am using a SqlDataReader to retrieve the
information to populate an ArrayList.

public ArrayList ReadHistory(int ItemPK)
{
SDrdr = SDcmd.ExecuteReader();
ArrayList AL = new ArrayList();

while(SDrdr.Read())
{
AL.Add(SDrdr["name"]);
}
return AL;
}

The web service is called from another project.

public ArrayList ReadHistory(int ItemPK)
{
wsrKeyCodeService.KeyCodeInformation WSR = new
wsrKeyCodeService.KeyCodeInformation();
ArrayList AL =
WSR.ReadKeyCodeHistory(VehiclePK);
return AL;

The problem is when I build the project I get the following error.
Cannot implicitly convert type 'object[]' to
'System.Collections.ArrayList'

When I change the type from ArrayList to Array…

public Array ReadHistory(int ItemPK)
{
wsrKeyCodeService.KeyCodeInformation WSR = new
wsrKeyCodeService.KeyCodeInformation();
Array AL = WSR.ReadHistory(ItemPK);
return AL;
}
The error goes away.

Apparently when the ArrayList is sent from the web service it is
converted to an Array.

Questions

1. Why does it do this?
2. What do I need to do to get an ArrayList on the receiving side? I
need to be able to resize the array. An Array can't be resized, the
ArrayList can.

Thanks for the help.

Nov 16 '05 #1
2 4895
This is not a C# question but here goes anyway. Comments inline:

<xm******@yahoo.com> wrote in message
news:40**************@news.dslextreme.com...

In a web service I am using a SqlDataReader to retrieve the
information to populate an ArrayList.

public ArrayList ReadHistory(int ItemPK)
{
SDrdr = SDcmd.ExecuteReader();
ArrayList AL = new ArrayList();

while(SDrdr.Read())
{
AL.Add(SDrdr["name"]);
}
return AL;
}

The web service is called from another project.

public ArrayList ReadHistory(int ItemPK)
{
wsrKeyCodeService.KeyCodeInformation WSR = new
wsrKeyCodeService.KeyCodeInformation();
ArrayList AL =
WSR.ReadKeyCodeHistory(VehiclePK);
return AL;

The problem is when I build the project I get the following error.
Cannot implicitly convert type 'object[]' to
'System.Collections.ArrayList'

When I change the type from ArrayList to Array.

public Array ReadHistory(int ItemPK)
{
wsrKeyCodeService.KeyCodeInformation WSR = new
wsrKeyCodeService.KeyCodeInformation();
Array AL = WSR.ReadHistory(ItemPK);
return AL;
}
The error goes away.

Apparently when the ArrayList is sent from the web service it is
converted to an Array.

Questions

1. Why does it do this?
Whatever you return from a WebMethod needs to be serializable to SOAP. The
type ArrayList is not serializable to SOAP so it gets converted to an array
of objects (object[]) which is SOAP serializable (provided the objects in
the array are SOAP serializable).
2. What do I need to do to get an ArrayList on the receiving side? I
need to be able to resize the array. An Array can't be resized, the
ArrayList can.


ArrayList al = new ArrayList(WSR.ReadHistory(ItemPK));

Regards,
Sami


Nov 16 '05 #2
Thank you. That solved it. :)

On Fri, 11 Jun 2004 17:07:51 +0300, "Sami Vaaraniemi"
<sa**********@pleasejippii.fi> wrote:
This is not a C# question but here goes anyway. Comments inline:

<xm******@yahoo.com> wrote in message
news:40**************@news.dslextreme.com...

In a web service I am using a SqlDataReader to retrieve the
information to populate an ArrayList.

public ArrayList ReadHistory(int ItemPK)
{
SDrdr = SDcmd.ExecuteReader();
ArrayList AL = new ArrayList();

while(SDrdr.Read())
{
AL.Add(SDrdr["name"]);
}
return AL;
}

The web service is called from another project.

public ArrayList ReadHistory(int ItemPK)
{
wsrKeyCodeService.KeyCodeInformation WSR = new
wsrKeyCodeService.KeyCodeInformation();
ArrayList AL =
WSR.ReadKeyCodeHistory(VehiclePK);
return AL;

The problem is when I build the project I get the following error.
Cannot implicitly convert type 'object[]' to
'System.Collections.ArrayList'

When I change the type from ArrayList to Array.

public Array ReadHistory(int ItemPK)
{
wsrKeyCodeService.KeyCodeInformation WSR = new
wsrKeyCodeService.KeyCodeInformation();
Array AL = WSR.ReadHistory(ItemPK);
return AL;
}
The error goes away.

Apparently when the ArrayList is sent from the web service it is
converted to an Array.

Questions

1. Why does it do this?


Whatever you return from a WebMethod needs to be serializable to SOAP. The
type ArrayList is not serializable to SOAP so it gets converted to an array
of objects (object[]) which is SOAP serializable (provided the objects in
the array are SOAP serializable).
2. What do I need to do to get an ArrayList on the receiving side? I
need to be able to resize the array. An Array can't be resized, the
ArrayList can.


ArrayList al = new ArrayList(WSR.ReadHistory(ItemPK));

Regards,
Sami


Nov 16 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: John P. Looney | last post by:
Yesterday, I installed service pack 4 + the latest hotfixes on some of my webservers. They run different websites, run by different people. The problem that all four developed was that any date...
0
by: Stephan Lux | last post by:
Hi all, I have developed a windows service with Visual Basic .NET which starts a file conversion tool via the commandline. The tool open the files (z.B. Word, Excel, Acrobat...) and prints them...
1
by: M DL via .NET 247 | last post by:
Hi all, i have one problem with a method of an xml web service that use a datetime data type input variable, and may be all is caused by international settings. The XML web service (localized...
1
by: Prashant | last post by:
We have an ATL COM server developed with VC++ 6.0 which acts a a server . Then we have VB6 modules Acting as clients and interfacing with the server . We want to migrate the ATL COM server...
0
by: pumaken68 | last post by:
Does anyone has experience with calling web service from pocket pc 2003 project in VS 2005 environment? I just migrated a smart device(pocket pc 2003) solution from VS 2003 to VS 2005. There are...
0
by: pwilliams | last post by:
NCOALink Change of Address Verification Each year over 40 million Americans change their mailing addresses. This change is equivalent to every person in California deciding to change addresses...
2
by: shyam | last post by:
I have a C++ COM based windows service which have more than 30k lines of code and which is stablized over years. We need to take the advantage of the ..NET framework for this project, especially...
0
by: iw3arv | last post by:
Hello, I've, probably, a simple problem but I'm not able to figure the solution!!! I've realized a web service method that reads an Excel sheet and convert the information in xml. This...
7
by: Rick | last post by:
I have a web service that I converted from VS 2003 Framework 1.1. to VS 2005 Framework 2.0. I tried to use the same IIS web site to run the web service. I deleted the Framework 1.1 files published...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.