ArrayList as parameter to WebService

  • Thread starter Thread starter Pete Hearn
  • Start date Start date
P

Pete Hearn

Hello All,

New to the whole C#/Webservice/ADO.NET thing, so apologies in advance if
this is a daft question!

I have a webservice which returns a dataset - no problem there and all very
standard. However, I want to pass an arraylist of objects to the method
which returns the dataset (the arraylist contains QBE parameter objects) but
the compiler chokes saying it wants an object[] array instead.

Is it not possible to pass an ArrayList as a param to WebServices, or am I
making a basic mistake here? I like the ArrayList because the number of
objects to pass over varies between calls, plus I can use the "foreach"
construct within the method which seems a neat feature of C#/

TIA
Peter
 
Hello!

And if you use the declarative _OrderItems.CopyTo(oi) it's not necessary to
have the procedural:
int i=0;
foreach(OrderItem o in _OrderItems)
{
oi=o;
i++;
}

Best regards,

Henrik Dahl

Peter Jausovec said:
Hi Pete,

Try at this link: http://garyshort.org/archive/2004/09/24/397.aspx

--
Regards,
Peter Jausovec
(http://blog.jausovec.net)
Pete Hearn said:
Hello All,

New to the whole C#/Webservice/ADO.NET thing, so apologies in advance if
this is a daft question!

I have a webservice which returns a dataset - no problem there and all
very
standard. However, I want to pass an arraylist of objects to the method
which returns the dataset (the arraylist contains QBE parameter objects)
but
the compiler chokes saying it wants an object[] array instead.

Is it not possible to pass an ArrayList as a param to WebServices, or am I
making a basic mistake here? I like the ArrayList because the number of
objects to pass over varies between calls, plus I can use the "foreach"
construct within the method which seems a neat feature of C#/

TIA
Peter
 
Guys - thank you for your replies: I have tried changing the webservice
parameter to an array of object, and also to an array of the specific class
concerned, but still without success. I either get XML generation errors or
the compiler bitches that the specific classes are different types even
though they are derived from a common library.

C# certainly makes me feel pretty stupid sometimes!!

To be able to continue working, I have coded the objects into a string using
a custom format, and I pass that into the webservice and reconstruct the
objects without problems; plus it can be any length to accommodate any
number of objects. A total bodge and doubtless horrendously bad practise,
but it works like a charm and has the merit of being blindingly simple.

Thanks again,
Pete

Henrik Dahl said:
Hello!

And if you use the declarative _OrderItems.CopyTo(oi) it's not necessary to
have the procedural:
int i=0;
foreach(OrderItem o in _OrderItems)
{
oi=o;
i++;
}

Best regards,

Henrik Dahl

Peter Jausovec said:
Hi Pete,

Try at this link: http://garyshort.org/archive/2004/09/24/397.aspx

--
Regards,
Peter Jausovec
(http://blog.jausovec.net)
Pete Hearn said:
Hello All,

New to the whole C#/Webservice/ADO.NET thing, so apologies in advance if
this is a daft question!

I have a webservice which returns a dataset - no problem there and all
very
standard. However, I want to pass an arraylist of objects to the method
which returns the dataset (the arraylist contains QBE parameter objects)
but
the compiler chokes saying it wants an object[] array instead.

Is it not possible to pass an ArrayList as a param to WebServices, or
am
 
Mr. Hearn,

That's a pitty of course.

I would like to recommend the Applied XML programming book from Microsoft
Press. In that book it's described how to deal with your issue.


Best regards,

Henrik Dahl

Pete Hearn said:
Guys - thank you for your replies: I have tried changing the webservice
parameter to an array of object, and also to an array of the specific class
concerned, but still without success. I either get XML generation errors or
the compiler bitches that the specific classes are different types even
though they are derived from a common library.

C# certainly makes me feel pretty stupid sometimes!!

To be able to continue working, I have coded the objects into a string using
a custom format, and I pass that into the webservice and reconstruct the
objects without problems; plus it can be any length to accommodate any
number of objects. A total bodge and doubtless horrendously bad practise,
but it works like a charm and has the merit of being blindingly simple.

Thanks again,
Pete

Henrik Dahl said:
Hello!

And if you use the declarative _OrderItems.CopyTo(oi) it's not necessary to
have the procedural:
int i=0;
foreach(OrderItem o in _OrderItems)
{
oi=o;
i++;
}

Best regards,

Henrik Dahl

Peter Jausovec said:
Hi Pete,

Try at this link: http://garyshort.org/archive/2004/09/24/397.aspx

--
Regards,
Peter Jausovec
(http://blog.jausovec.net)
Hello All,

New to the whole C#/Webservice/ADO.NET thing, so apologies in
advance
if
this is a daft question!

I have a webservice which returns a dataset - no problem there and all
very
standard. However, I want to pass an arraylist of objects to the method
which returns the dataset (the arraylist contains QBE parameter objects)
but
the compiler chokes saying it wants an object[] array instead.

Is it not possible to pass an ArrayList as a param to WebServices,
or
number
 
Thanks Henrik - I will get a copy of that book, because I ought to learn the
"proper" way to do this stuff!

Regards,
Pete

Henrik Dahl said:
Mr. Hearn,

That's a pitty of course.

I would like to recommend the Applied XML programming book from Microsoft
Press. In that book it's described how to deal with your issue.


Best regards,

Henrik Dahl

Pete Hearn said:
Guys - thank you for your replies: I have tried changing the webservice
parameter to an array of object, and also to an array of the specific class
concerned, but still without success. I either get XML generation
errors
or
the compiler bitches that the specific classes are different types even
though they are derived from a common library.

C# certainly makes me feel pretty stupid sometimes!!

To be able to continue working, I have coded the objects into a string using
a custom format, and I pass that into the webservice and reconstruct the
objects without problems; plus it can be any length to accommodate any
number of objects. A total bodge and doubtless horrendously bad practise,
but it works like a charm and has the merit of being blindingly simple.

Thanks again,
Pete

Henrik Dahl said:
Hello!

And if you use the declarative _OrderItems.CopyTo(oi) it's not
necessary
to
have the procedural:
int i=0;
foreach(OrderItem o in _OrderItems)
{
oi=o;
i++;
}

Best regards,

Henrik Dahl

Hi Pete,

Try at this link: http://garyshort.org/archive/2004/09/24/397.aspx

--
Regards,
Peter Jausovec
(http://blog.jausovec.net)
Hello All,

New to the whole C#/Webservice/ADO.NET thing, so apologies in
advance
if
this is a daft question!

I have a webservice which returns a dataset - no problem there and all
very
standard. However, I want to pass an arraylist of objects to the method
which returns the dataset (the arraylist contains QBE parameter objects)
but
the compiler chokes saying it wants an object[] array instead.

Is it not possible to pass an ArrayList as a param to WebServices,
or
am
I
making a basic mistake here? I like the ArrayList because the
number
of
objects to pass over varies between calls, plus I can use the "foreach"
construct within the method which seems a neat feature of C#/

TIA
Peter

 
Back
Top