Web Service Data Conversion Problem

X

xmail123

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.
 
S

Sami Vaaraniemi

This is not a C# question but here goes anyway. Comments inline:

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
 
X

xmail123

Thank you. That solved it. :)

This is not a C# question but here goes anyway. Comments inline:

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
 
K

kalpanaganeshm

Informatics Outsourcing is an Offshore Data Management service company. Data Management Service includes all types of Data Conversion, File Conversion, XML Conversion, HTML Conversion,SGML Conversion, Document Conversion,DataEntry, Data Extraction and Validation,OCR and ICR Services with affordableprice. Our team to give the solution quickly and given requirements.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top