Geeks With Blogs
Wayne Magnum's Blog
This post below will show you how to pass a custom collection as a parameter to the webservice.
Create a custom collection class...
public class Person
public int Age;
public string FName, LName;
public Person() { }
public Person(string fname, string lname, int age)
Age = age;
FName = fname;
LName = lname;
Create a Web Method...
public void Method(Person[] fields, bool attachmentincluded)
           System.Collections.Generic.List<Person> people = new List<Person>(fields);
            foreach (Person i in people)
                string F, L;
                int A;
                F =i.FName;
                L = i.LName;
                A = i.Age;
In the consumer application...
     //Create People...
     localhost.Person john = new localhost.Person();
     john.FName = "John";
     john.LName = "Doe";
     john.Age = 37;
     localhost.Person jane = new localhost.Person();
     jane.FName = "Jane";
     jane.LName = "Doe";
     jane.Age = 37;
     //Create array
     localhost.Person[] people = { john, jane };
     //Call Web Service
     localhost.Service1 s = new localhost.Service1();
     s.Method(people, false);


Posted on Thursday, January 24, 2008 8:13 AM DotNet | Back to top

Comments on this post: Custom Collection Parameter in a Web Service

# re: Custom Collection Parameter in a Web Service
Requesting Gravatar...
You have to define person class in web server project. When you add web service reference to your client, client side will have same class..
Left by Hakan Kutluay on Jun 23, 2009 1:42 AM

# re: Custom Collection Parameter in a Web Service
Requesting Gravatar...
The training kit is very helpful. It contains some basic information regarding Visual Studio 11. The software is indeed advanced and many are using this because of its practicality and advanced features.
Left by Nancy Alcorn on Jan 06, 2012 11:24 PM

Your comment:
 (will show your gravatar)

Copyright © Wayne H Magnum | Powered by: