I've managed to write a service that returns an array in XML when tested by itself with no problems, but when I try and get my webpage to consume it I'm having difficulties
Here's my service simplified:
- public struct ListData
-
{public string id, title, subtitle;}
-
-
[WebMethod]
-
public ListData[] GetListData()
-
{
-
int x = 0;
-
int number = 0;
-
ListData[] List = null;
-
List = new ListData[5];
-
-
while (x < 5)
-
{
-
List[x].id = "subtitle test" + System.Convert.ToString(x);
-
List[x].title = "subtitle test" + System.Convert.ToString(x);
-
List[x].subtitle = "subtitle test" + System.Convert.ToString(x);
-
x++;
-
}
-
-
Return List;
-
}
The consuming page has had countless versions of this:
- localhost.Service myws = new localhost.Service();
-
localhost.ListData list = new localhost.ListData();
-
list = myws.GetListData();
-
-
Label1.Text = "Test data: <br/> " + list[0].Title + list[1].Subtitle + list[2].id;
-
I've tried so many combinations and Googled everywhere but I just can't seem to get it to work :(
I'm quite new at this so if anyone has any ideas I'd really appreciate it!
ok i see you have several small bugs here.
first thing you should see:
- public ListData[] GetListData()
this method returns a an array of ListData objects. not a single ListData object
so the client app here:
- list = myws.GetListData();
expects you to assign the returning array to an array of ListData.
so the solution to that would be:
- localhost.ListData[] list;
-
list = myws.GetListData();
then i see you user different indexes to access info in the ListData Array
- Label1.Text = "Test data: <br/> " + list[0].Title + list[1].Subtitle + list[2].id;
I assume u wish to access attributes of a single and same ListData object
so you should use it this way:
- Label1.Text = "Test data: <br/> " + list[0].Title + list[0].Subtitle + list[0].id;
Hope this helps!