Passing an ArrayList to a web service

R

Russ

I need to pass a variable list of arrays to a web service. The web
service is C++ and the WebMethod is declared:

[System::Web::Services::WebMethod (Description="Submit Check.")]
bool SubmitCheck (UINT empno, ArrayList* List);

It is expecting an ArrayList consisting of an undetermined number of
arrays of type double. In this case all the arrays have the same
dimension (9).

In my Web Client I create an ArrayList containing some double arrays,
and then try to pass it like:

ws.SubmitCheck (m_Empno, (object[]) List.ToArray (typeof (double)));

I get the error "InvalidCastException: At least one element in the
source array could not be cast down to the destination array type".

I've tried a number of variations but nothing works, or makes much
sense to me. How can I accomplish this?

Thanks Russ
 
D

Daryl Davis

Using VB I can call an array by below, although I am unsure about C++, that
is part of my project next month.

<WebMethod(Description:="")> _

Public Overridable Function GetCards( ByRef sCardSpots As String(), ByRef
sFaceNum As String()) As Integer

Daryl Davis
 
R

Russ

I can pass an array with no problem too. But this is an ArrayList.

Can anyone else help?

Thanks, Russ

Using VB I can call an array by below, although I am unsure about C++, that
is part of my project next month.

<WebMethod(Description:="")> _

Public Overridable Function GetCards( ByRef sCardSpots As String(), ByRef
sFaceNum As String()) As Integer

Daryl Davis


Russ said:
I need to pass a variable list of arrays to a web service. The web
service is C++ and the WebMethod is declared:

[System::Web::Services::WebMethod (Description="Submit Check.")]
bool SubmitCheck (UINT empno, ArrayList* List);

It is expecting an ArrayList consisting of an undetermined number of
arrays of type double. In this case all the arrays have the same
dimension (9).

In my Web Client I create an ArrayList containing some double arrays,
and then try to pass it like:

ws.SubmitCheck (m_Empno, (object[]) List.ToArray (typeof (double)));

I get the error "InvalidCastException: At least one element in the
source array could not be cast down to the destination array type".

I've tried a number of variations but nothing works, or makes much
sense to me. How can I accomplish this?

Thanks Russ
 
R

Russ

Some additional information. After reading a lot of posts and info on
the internet that seems to 'almost' address the issue, I tried
changing the generated proxy code from object[] List, to
'System.Collections.ArrayList List", both in the attribute and the
begin code. But when I try it I still get the same error as before:

[InvalidOperationException: The type System.Double[] may not be used
in this context.]

My ArrayList is composed as shown below:
ArrayList List = new ArrayList ();

foreach (...) {
double [] ra = new double [9];
List.Add (ra);
}
ws.SubmitCheck (m_Empno, List);

So it seems that the XML serializer does not like arrays of doubles.
Why not? Double is a primitive type.

Anyway, still looking for a solution.

Thanks, Russ
 
D

Dino Chiesa [Microsoft]

you are attempting to convert an arraylist
to which you have added "arrays of double"
to an array of double

it doesn't work that way. You would better succeed converting the
arraylist to an array of Array of double.

double[][]
 
R

Russ

Hi DIno. I already tried that with no success. I got the same error
when I did:

double [][] d1 = { new double [9], new double [9] };
d1 = (double [][]) List.ToArray (typeof (double[]));
ws.SubmitCheck (d1);

Also, the above, even if it worked, is not satisfactory because it
requires me to know the first dimension of d1 at compile time, which I
do not.

Could you please tell me how to make this work? I have been reading
about using XmlIncludeAttribute to help, but I could not find a C++
example and from the C# example I could not determine where I should
put the new code. I thought I could use XmlIncludeAttribute to tell
the serializer to expect an array of doubles.

I really do not want to use a double [][] array for this. That is why
I am using the ArrayList in the first place. I am certainly open to
any other solutions that meet my requirements.

Thank you, Russ

you are attempting to convert an arraylist
to which you have added "arrays of double"
to an array of double

it doesn't work that way. You would better succeed converting the
arraylist to an array of Array of double.

double[][]




Russ said:
I need to pass a variable list of arrays to a web service. The web
service is C++ and the WebMethod is declared:

[System::Web::Services::WebMethod (Description="Submit Check.")]
bool SubmitCheck (UINT empno, ArrayList* List);

It is expecting an ArrayList consisting of an undetermined number of
arrays of type double. In this case all the arrays have the same
dimension (9).

In my Web Client I create an ArrayList containing some double arrays,
and then try to pass it like:

ws.SubmitCheck (m_Empno, (object[]) List.ToArray (typeof (double)));

I get the error "InvalidCastException: At least one element in the
source array could not be cast down to the destination array type".

I've tried a number of variations but nothing works, or makes much
sense to me. How can I accomplish this?

Thanks Russ
 
R

Russ

For instance, I found this in an online article:

<WebMethod()> Public Function GetData() As _
<XmlArrayItemAttribute(GetType(Customer))> ArrayList

If my web service was written in VB, I would try doing:

<WebMethod()> Public Function SubmitCheck() As _
<XmlArrayItemAttribute(GetType(double[]))> ArrayList

But I can't deduce what the syntax would be in my C++ web service...

Russ


Hi DIno. I already tried that with no success. I got the same error
when I did:

double [][] d1 = { new double [9], new double [9] };
d1 = (double [][]) List.ToArray (typeof (double[]));
ws.SubmitCheck (d1);

Also, the above, even if it worked, is not satisfactory because it
requires me to know the first dimension of d1 at compile time, which I
do not.

Could you please tell me how to make this work? I have been reading
about using XmlIncludeAttribute to help, but I could not find a C++
example and from the C# example I could not determine where I should
put the new code. I thought I could use XmlIncludeAttribute to tell
the serializer to expect an array of doubles.

I really do not want to use a double [][] array for this. That is why
I am using the ArrayList in the first place. I am certainly open to
any other solutions that meet my requirements.

Thank you, Russ

you are attempting to convert an arraylist
to which you have added "arrays of double"
to an array of double

it doesn't work that way. You would better succeed converting the
arraylist to an array of Array of double.

double[][]




Russ said:
I need to pass a variable list of arrays to a web service. The web
service is C++ and the WebMethod is declared:

[System::Web::Services::WebMethod (Description="Submit Check.")]
bool SubmitCheck (UINT empno, ArrayList* List);

It is expecting an ArrayList consisting of an undetermined number of
arrays of type double. In this case all the arrays have the same
dimension (9).

In my Web Client I create an ArrayList containing some double arrays,
and then try to pass it like:

ws.SubmitCheck (m_Empno, (object[]) List.ToArray (typeof (double)));

I get the error "InvalidCastException: At least one element in the
source array could not be cast down to the destination array type".

I've tried a number of variations but nothing works, or makes much
sense to me. How can I accomplish this?

Thanks Russ
 
R

Russ

Ok, I have this working now, so no need to respond. I can see that my
last post was going off in the wrong direction.

I solved the problem by creating a new class to hold my ArrayList of
double arrays. Then I pass an instance of the class - this works
fine. It sure seems strange that I can pass an ArrayList of double
arrays as part of a class, but not by itself.

Anyway, making it part of a class is where I wanted to go all along -
I just thought I would try the simpler? way first.

Russ
 

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

Members online

Forum statistics

Threads
473,774
Messages
2,569,596
Members
45,132
Latest member
TeresaWcq1
Top