By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,920 Members | 1,660 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,920 IT Pros & Developers. It's quick & easy.

ArrayList as parameter to WebService

P: n/a
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
Nov 16 '05 #1
Share this Question
Share on Google+
5 Replies


P: n/a
Hi Pete,

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

--
Regards,
Peter Jausovec
(http://blog.jausovec.net)
"Pete Hearn" <tr***************@virgin.net> wrote in message
news:e3**************@TK2MSFTNGP09.phx.gbl...
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

Nov 16 '05 #2

P: n/a
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[i]=o;
i++;
}

Best regards,

Henrik Dahl

"Peter Jausovec" <pe***@jausovec.net> wrote in message
news:uH**************@TK2MSFTNGP15.phx.gbl...
Hi Pete,

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

--
Regards,
Peter Jausovec
(http://blog.jausovec.net)
"Pete Hearn" <tr***************@virgin.net> wrote in message
news:e3**************@TK2MSFTNGP09.phx.gbl...
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


Nov 16 '05 #3

P: n/a
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" <He********@community.nospam> wrote in message
news:uf**************@TK2MSFTNGP10.phx.gbl...
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[i]=o;
i++;
}

Best regards,

Henrik Dahl

"Peter Jausovec" <pe***@jausovec.net> wrote in message
news:uH**************@TK2MSFTNGP15.phx.gbl...
Hi Pete,

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

--
Regards,
Peter Jausovec
(http://blog.jausovec.net)
"Pete Hearn" <tr***************@virgin.net> wrote in message
news:e3**************@TK2MSFTNGP09.phx.gbl...
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



Nov 16 '05 #4

P: n/a
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" <tr***************@virgin.net> wrote in message
news:Oh**************@TK2MSFTNGP10.phx.gbl...
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" <He********@community.nospam> wrote in message
news:uf**************@TK2MSFTNGP10.phx.gbl...
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[i]=o;
i++;
}

Best regards,

Henrik Dahl

"Peter Jausovec" <pe***@jausovec.net> wrote in message
news:uH**************@TK2MSFTNGP15.phx.gbl...
Hi Pete,

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

--
Regards,
Peter Jausovec
(http://blog.jausovec.net)
"Pete Hearn" <tr***************@virgin.net> wrote in message
news:e3**************@TK2MSFTNGP09.phx.gbl...
> 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
>
>



Nov 16 '05 #5

P: n/a
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" <He********@community.nospam> wrote in message
news:uA**************@TK2MSFTNGP15.phx.gbl...
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" <tr***************@virgin.net> wrote in message
news:Oh**************@TK2MSFTNGP10.phx.gbl...
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" <He********@community.nospam> wrote in message
news:uf**************@TK2MSFTNGP10.phx.gbl...
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[i]=o;
i++;
}

Best regards,

Henrik Dahl

"Peter Jausovec" <pe***@jausovec.net> wrote in message
news:uH**************@TK2MSFTNGP15.phx.gbl...
> Hi Pete,
>
> Try at this link: http://garyshort.org/archive/2004/09/24/397.aspx
>
> --
> Regards,
> Peter Jausovec
> (http://blog.jausovec.net)
> "Pete Hearn" <tr***************@virgin.net> wrote in message
> news:e3**************@TK2MSFTNGP09.phx.gbl...
> > 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
> >
> >
>
>



Nov 16 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.