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# / March 2008

Tip: Looking for answers? Try searching our database.

Make a web service method return a class

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Danny Ni - 25 Mar 2008 05:47 GMT
Hi,

How do I make a web method to return an object class MyClass, also how do I
make it to return List<MyClass>?

TIA
Marc Gravell - 25 Mar 2008 06:19 GMT
If you mean an asmx-style web-service, then something like below - but
note that the remote proxy won't get the exact same class
representation but a lightweight data abstraction (and quite likely a
MyClass[] at the caller). With WCF it is possible to use either the
proxy approach, or via assembly-sharing you can use the exact same
class.

Marc

[Serializable]
public class MyClass {...}

[WebMethod]
public MyClass Foo(...) {...}

[WebMethod]
public List<MyClass> Bar(...) {...}
Arne Vajhøj - 29 Mar 2008 20:23 GMT
> How do I make a web method to return an object class MyClass, also how do I
> make it to return List<MyClass>?

Returning a MyClass is straigth forward. Make sure that MyClass
is following proper paradigms about private fields and public
properties.

You should not return a List<MyClass> from a web service but
instead a MyClass[], because List is .NET specific.

(I believe that List<MyClass> will be exposed as MyClass[], so
it will work, but be a bit confusing)

Arne

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.