Geeks With Blogs
AzamSharp Some day I will know everything. I hope that day never comes.

These days I am working on a Project in which I need to implement a Service Oriented Architecture. The services are exposed as Web Services. I was planning to return the List<User> to the client but found out that List cannot be returned since its not serializable. I plan to use ArrayList and that worked. If you would like to return an ArrayList from the WebService you can do so check out the simple code below:

 [WebMethod]
    [System.Xml.Serialization.XmlInclude(
typeof(User))]
    
public  ArrayList GetAllUsers()
    {
        User user = 
new User();
        
return user.GetAllUsers();
    }

Above is your WebMethod and below is the defination of the class User:

 [Serializable]
    
public class User
    {           
        
        
/* PRIVATE FIELDS */
        
private int _userID;
        
private string _firstName; 
        
private string _lastName;

        
/* PUBLIC PROPERTIES */
        
public int UserID
        {
            
get return _userID; }
            
set { _userID = value; } 
        }

Pretty Simple Right!

 


powered by IMHO 1.3

Posted on Wednesday, February 15, 2006 7:00 PM | Back to top


Comments on this post: Returning ArrayList from a WebService

# re: Returning ArrayList from a WebService
Requesting Gravatar...
Hey I remember this from DOC
Left by sheysrebellion on Feb 15, 2006 7:41 PM

# re: Returning ArrayList from a WebService
Requesting Gravatar...
You might have shown how you write the call to the web service
Left by K on Apr 07, 2006 8:15 PM

# re: Returning ArrayList from a WebService
Requesting Gravatar...
can u describe that in Visual Basic ?
Left by re on Jun 20, 2006 3:41 PM

# re: Returning ArrayList from a WebService
Requesting Gravatar...
Hi,
You will compile this code, but if you call GetAllUsers() from instance of Web Service, it retrieve you Array of System.objects , not ArrayList.
Left by k0nd on Jul 22, 2006 6:53 AM

# re: Returning ArrayList from a WebService
Requesting Gravatar...
Hi was searching for the same solution...thanks a lot.
Left by Nikhil on Sep 26, 2006 2:56 AM

# re: Returning ArrayList from a WebService
Requesting Gravatar...
Tks dude!, This was great, I was with this same issue on my project.
Left by Rodrigo on Apr 03, 2007 2:02 AM

# re: Returning ArrayList from a WebService
Requesting Gravatar...
Can u plz show how to call this web mothod from client application?
Left by monal on Apr 20, 2007 9:41 AM

# re: Returning ArrayList from a WebService
Requesting Gravatar...
I was looking for this thing;and now I've it.Thanks a lot...
Left by Mukadder on Aug 09, 2007 1:44 AM

# re: Returning ArrayList from a WebService
Requesting Gravatar...
God bless you. thanks!
Left by Jawz on May 06, 2008 2:26 AM

# re: Returning ArrayList from a WebService
Requesting Gravatar...
how 'bout the other way 'round...? i would like to send an arraylist back to the web service but it wants an array of objects. how to do the conversion to keep the service happy?

thanks in advance.
Left by kjward on May 21, 2008 4:37 AM

# re: Returning ArrayList from a WebService
Requesting Gravatar...
But while consuming, how will i consume an arraylist, it throws an error saying it will give you as an object[] or xml value and need to convert it again to arraylist?
Left by Smitha on Jun 17, 2008 10:48 PM

Your comment:
 (will show your gravatar)


Copyright © Mohammad Azam | Powered by: GeeksWithBlogs.net