all groups > dotnet web services > april 2007 >
You're in the

dotnet web services

group:

returning generics


returning generics piter
4/29/2007 12:43:11 PM
dotnet web services:
Hi
Can generics be returned by the WebMethod?
Iam thinking about <List>.
Anyways where can i find list of all values that can be actually passed o
returned within webservice connection?
Thanks
PK
Re: returning generics John Cosmas
5/29/2007 11:48:04 AM
Yes, I read somewhere in the forums it is possible. But I'm trying to find
a good example to use myself. I'm considering a collection, because it's a
known type and structured, but I still can't find a working example
anywhere. I wish that people who post solutions would actually give us good
examples instead of one liners that go nowhere. It's interesting that I
don't have such problems in the VBA forums. If I run into anything, I will
let you know.

John

[quoted text, click to view]

Re: returning generics John Saunders [MVP]
5/29/2007 2:50:23 PM
[quoted text, click to view]

John et. al.,

I'm sorry I haven't been able to provide better or more detailed answers.
I've got a release due Monday and have little time left over for helping
out.

Briefly, though, I want to caution everyone about using platform-specific
types in web services, either as parameters or return values. The Web
Services infrastructure was meant to be platform-neutral. In this regard,
consider that many platforms have no concept of generics.

Further, consider that a generic method does not represent a single method.
Rather, it represents a family of methods. This would make it even more
complicated to implement in a cross-platform manner.

That said, I believe you can get a web service to return a generic
instantiation:

[WebMethod]
public MyGeneric<int, string> MyGenericMethod(int x, string y);

I believe I've seen a generated WSDL for such a method containing a
manufactured name containing "int" and "string". Something like
"MyGenericOfIntAndString".

Much the same comment applies to things like List<T>. In this case, you
might be able to use XML Serialization attributes to turn this into an array
of T.

I would recommend that any developers new to Web Services should start off
by programming against the "least-common denominator" model that will work
on any platform. For instance, if you want to use List<T> inside of your web
service, go ahead - but you'll be better off (*) working with an array of T
(for a specific T). This will correspond better to what the infrastructure
is geared to send and receive.
--
John Saunders [MVP]

(*) After gaining experience with the basics of the infrastructure, go ahead
and challenge it. You will by then understand how things work "under the
covers", and you'll be in a better position to learn how to make Web
Services "do tricks".

AddThis Social Bookmark Button