Groups | Blog | Home
all groups > dotnet web services > january 2008 >

dotnet web services : Returning an ArrayList of Custom Objects From a Web Service


Drew
1/16/2008 9:24:03 AM
I have a current requirement to all a subsidiary to use a current legacy
application and interface with my new system to inject data when appropriate.
I wanted to create a web service since we are both .Net shops and this would
seem to be the easiest method. But I ran into one snafu. I wanted to return
to the subsidiary an ArrayList of my Organization objects which contain the
orgs id, name etc. so they can use that information in the data insert call.

I have done a lot of looking around but have not found the answer yet to
accomplish this. Here is some of the code:

1. Web service calls an object manager which returns the ArrayList:
1. ArrayList _array = ObjectManager.Instance.GetAllOrgs();
2. Object manager calls the object data store returning ArrayList
1. ObjectStore.Instance.GetAllOrgs();
3. Object store makes database call, passes reader to method that loops
over results building an Org object and adding it to an array.:
1. public ArrayList GetAllOrgs()
{
ArrayList orgs = new ArrayList();

using (SqlConnection connection = new
SqlConnection(_connectionString))
{
connection.Open();

SqlCommand command = new SqlCommand();

command.Connection = connection;
command.CommandType = CommandType.StoredProcedure;
command.CommandText = "usp_GetOrgs";

SqlDataReader reader =
command.ExecuteReader(CommandBehavior.SingleResult);

orgs = CreateOrgs(reader);

}

return orgs;
}

That is my issue in a nutshell - my web page that consumes the web service
does not know how to cope with the ArrayList with Org objects in it.

Any help would be much appreciated!
SharePoint Tips and Tricks
Spam Catcher
1/16/2008 6:52:09 PM
=?Utf-8?B?RHJldw==?= <Drew@discussions.microsoft.com> wrote in
news:69B35C1A-7037-409A-8079-787305E45577@microsoft.com:

[quoted text, click to view]

Try using a basic array, rather than an ArrayList.

--
Misbah Arefin
1/16/2008 11:59:01 PM
use the following attributes for your webmethod

[XmlInclude(typeof(ArrayList))]
[XmlInclude(typeof(Org))]



--
Misbah Arefin



[quoted text, click to view]
AddThis Social Bookmark Button