Hi,
I am implementing web services and try to return a collection of records,
say
1,"John","Doe",1/1/1990
2,"Jane","Doe",2/1/1990
3,"Joe","Smith",3/1/1990
......
In my c# project I have a class that implements ICollection to provide these
data.
When I try to make web method to return the class, I got :
The return type of .... is not CLS-compliant.
What is the best way to return a collection of records from a web method?
TIA
Peter Bromberg [C# MVP] - 13 Nov 2006 19:54 GMT
Create a "Record" class with fields corresponding to the CSV data you posted,
and mark it as serializable. Your webservice will be happy to return an array
of these.
Peter

Signature
Co-founder, Eggheadcafe.com developer portal:
http://www.eggheadcafe.com
UnBlog:
http://petesbloggerama.blogspot.com
> Hi,
>
[quoted text clipped - 15 lines]
>
> TIA
ssamuel - 13 Nov 2006 20:00 GMT
Your question tells us what your data looks like, but nothing about
what the return type of your function is. Can you post the signature of
the web service-visible method, as well as an outline of any
non-framework types that may be used in that signature?
As for the "best way" to do it, that's probably to create a shell
return type struct or class and dump that. The web service framework
will automatically serialize it as XML:
public struct myReturnType
{
public int ID;
public string FirstName;
public string LastName;
public DateTime Date;
}
If your method has the following signature:
[WebMethod]public myReturnType[] GetRecords(...) { ... }
you'll get back something vaguely like:
<GetRecords>
<myReturnType>
<ID>1</ID>
<FirstName>John</FirstName>
...
</myReturnType>
<myReturnType>
<ID>2</ID>
...
</myReturnType>
...
</GetRecords>
That's about the best way to use web services.
Stephan
> Hi,
>
[quoted text clipped - 15 lines]
>
> TIA