Paul Mendoza C# blog
Friday, January 05, 2007
  Return multiple values from a web service

At some point you’re going to find it useful to return a few different values at a time. The best way to do this is to actually create an object that will contain all the values that you will need to return and then pass that back as the return value.



For example, in the screenshot above, I’ve created a small class that initializes it’s public variables and then returns that newly created object. Once we look at the resultant XML, it will be clear what happened.

Picture

And then when we test the web service, the following XML is returned. Notice that the XML node names correspond to the names of the variables in the object that was returned.

But next, we’re going to look at how to actually use all of this XML data. Please, please, please don’t just create XML parsers. You need to be code generating and Microsoft has made generating code for web services incredibly easy if you’re using one of their .NET technologies. If you’re not, I have no idea what you do then but let’s assume we’re not in that predicament.

 
Comments:
I receive: Error Cannot implicitly convert type 'ReturnObject' to 'string' error.

Any ideas?
 
Maybe the ReturnObject class must be made as serializable ...
 
Doublecheck your WebMethod, sounds like the return type is still set to string
 
Post a Comment





<< Home
I am currently an ASP.NET, C# developer working on MangosteenNation.com, a XanGo website for helping people build their businesses. I am also pursuing a degree at CSU San Marcos in Southern California.

XanGo at Mangosteen Nation

Archives
October 2005 / November 2005 / December 2005 / January 2006 / February 2006 / March 2006 / April 2006 / May 2006 / June 2006 / July 2006 / August 2006 / September 2006 / October 2006 / November 2006 / December 2006 / January 2007 / April 2007 / May 2007 / June 2007 / August 2007 / February 2008 / August 2008 /


Powered by Blogger

Subscribe to
Posts [Atom]