[WebMethod]
public Member getMemberInfo() {
return new Member("Larry Collette");
}
This is how I invoke this web service (above) from the client:
private void getMyMemberInfo() {
DemoWebService.Member me = DemoWebService.Service().getMemberInfo();
TextBox1.Text = me.MyName;
}
This all works ok... now what if I wanted a collection of members?
[WebMethod]
public Member[] getTeamInfo() {
Members[] myMembers = {
new Member("Larry"),
new Member("Matt"),
new Member("Joe")
}
return myMembers;
}
This is how I invoke this web service (above) from the client:
private void getMyMembers() {
DemoWebService.Member[] team
= DemoWebService.Service().getTeamInfo();
TextBox1.Text = team[0].MyName; //gets value Larry
TextBox2.Text = team[1].MyName; //gets value Matt
TextBox3.Text = team[2].MyName; //gets value Joe
}
If I binding the above to a BindingSource class or DataGridView, it is not sortable. You can also try this, instead of an the type array, but....
[WebMethod]
public ArrayList getTeamInfoArrayList() {
ArrayList myMembers = new ArrayList();
myMembers.add(new Member("Larry"));
myMembers.add(new Member("Matt"));
myMembers.add(new Member("Joe"));
return myMembers;
}
Now, what do you think when this method is invoked what do you get? An ArrayList data type? Wrong... guess... a stupid Object...... you guessed it [] array. So I take the array and reconvert it back to the ArrayList. Now... can I cast this Array Object[] to ArrayList... nope. I have to loop through each item in the Object[] and add it to the ArrayList. Using a CollectionBase class is also no different.
private void getMyMembersArrayList() {
Object[] team
= DemoWebService.Service().getTeamInfoArrayList();
ArrayList myTeam = new ArrayList();
for (int i=0; i<team.length; i++) {
myTeam.add((DemoWebService.Member)team[i]);
}
DataGridView1.DataSource = myTeam;
TextBox1.Text = myTeam[0].MyName; //gets value Larry
TextBox2.Text = myTeam[1].MyName; //gets value Matt
TextBox3.Text = myTeam[2].MyName; //gets value Joe
}
Now with the data... I still can't sort or filter it. So now I have to create a method with recursive loop to send each element value and types to a local Member() class that inherits the CollectionBase() class and interfaces the IBindData() class, so I can allow sorting and filtering. Also I want to put this data into an XML that is saved locally. I haven't gotten that far yet. Since my Members() class have properties that I cannot loop through each "Column" and "Row" like I could with DataTables, I have to use those nasty nested for loops on the Object arrays. Yipppie.
On another note about testing an Invoke to a Method that returns a DataTable... I haven't figured it out yet. The Web Reference in the Windows App show that method as a DataSource and an 'ANY' and 'ANY1' XMLElement[] type... I tried to use it, but was not successful in getting my data from it. I can only assume it IS xml, but to extract the data?? All the properties point to null.... kinda odd.
Posted
01-31-2006 9:41 PM
by
LarryZonka