Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / C# / November 2006

Tip: Looking for answers? Try searching our database.

Return complex data type from a web method

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
John - 13 Nov 2006 19:02 GMT
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

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.