473,385 Members | 1,359 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Problems returning array from a service

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:

Expand|Select|Wrap|Line Numbers
  1.  public struct ListData
  2.    {public string id, title, subtitle;}
  3.  
  4. [WebMethod]
  5.    public ListData[] GetListData()
  6.    {
  7.       int x = 0;
  8.       int number = 0;
  9.       ListData[] List = null;
  10.       List = new ListData[5];
  11.  
  12.       while (x < 5)
  13.              {         
  14.          List[x].id =  "subtitle test" + System.Convert.ToString(x);
  15.          List[x].title =  "subtitle test" + System.Convert.ToString(x);
  16.          List[x].subtitle = "subtitle test" + System.Convert.ToString(x);
  17.          x++;
  18.             }
  19.  
  20.       Return List;
  21.    }

The consuming page has had countless versions of this:

Expand|Select|Wrap|Line Numbers
  1.  localhost.Service myws = new localhost.Service();
  2.       localhost.ListData list = new localhost.ListData();
  3.       list = myws.GetListData();
  4.  
  5.       Label1.Text = "Test data: <br/> " + list[0].Title + list[1].Subtitle + list[2].id;
  6.  
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!
Mar 31 '08 #1
4 911
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:

Expand|Select|Wrap|Line Numbers
  1.  public struct ListData
  2.    {public string id, title, subtitle;}
  3.  
  4. [WebMethod]
  5.    public ListData[] GetListData()
  6.    {
  7.       int x = 0;
  8.       int number = 0;
  9.       ListData[] List = null;
  10.       List = new ListData[5];
  11.  
  12.       while (x < 5)
  13.              {         
  14.          List[x].id =  "subtitle test" + System.Convert.ToString(x);
  15.          List[x].title =  "subtitle test" + System.Convert.ToString(x);
  16.          List[x].subtitle = "subtitle test" + System.Convert.ToString(x);
  17.          x++;
  18.             }
  19.  
  20.       Return List;
  21.    }

The consuming page has had countless versions of this:

Expand|Select|Wrap|Line Numbers
  1.  localhost.Service myws = new localhost.Service();
  2.       localhost.ListData list = new localhost.ListData();
  3.       list = myws.GetListData();
  4.  
  5.       Label1.Text = "Test data: <br/> " + list[0].Title + list[1].Subtitle + list[2].id;
  6.  
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!
Exactly what difficulties are you having?
Mar 31 '08 #2
I can't seem to get the values into the "list" variable in the consuming website.
I keep getting errors like
"Cannot implicitly convert type 'localhost.ListData[]' to 'localhost.ListData'" or
"Cannot apply indexing with [] to an expression of type 'localhost.ListData'"
and seem to be getting nowhere
Mar 31 '08 #3
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:

Expand|Select|Wrap|Line Numbers
  1.  public struct ListData
  2.    {public string id, title, subtitle;}
  3.  
  4. [WebMethod]
  5.    public ListData[] GetListData()
  6.    {
  7.       int x = 0;
  8.       int number = 0;
  9.       ListData[] List = null;
  10.       List = new ListData[5];
  11.  
  12.       while (x < 5)
  13.              {         
  14.          List[x].id =  "subtitle test" + System.Convert.ToString(x);
  15.          List[x].title =  "subtitle test" + System.Convert.ToString(x);
  16.          List[x].subtitle = "subtitle test" + System.Convert.ToString(x);
  17.          x++;
  18.             }
  19.  
  20.       Return List;
  21.    }

The consuming page has had countless versions of this:

Expand|Select|Wrap|Line Numbers
  1.  localhost.Service myws = new localhost.Service();
  2.       localhost.ListData list = new localhost.ListData();
  3.       list = myws.GetListData();
  4.  
  5.       Label1.Text = "Test data: <br/> " + list[0].Title + list[1].Subtitle + list[2].id;
  6.  
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:
Expand|Select|Wrap|Line Numbers
  1. public ListData[] GetListData()
this method returns a an array of ListData objects. not a single ListData object
so the client app here:
Expand|Select|Wrap|Line Numbers
  1. list = myws.GetListData();
expects you to assign the returning array to an array of ListData.

so the solution to that would be:
Expand|Select|Wrap|Line Numbers
  1. localhost.ListData[] list;
  2. list = myws.GetListData();
then i see you user different indexes to access info in the ListData Array
Expand|Select|Wrap|Line Numbers
  1. 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:
Expand|Select|Wrap|Line Numbers
  1. Label1.Text = "Test data: <br/> " + list[0].Title + list[0].Subtitle + list[0].id;
Hope this helps!
Mar 31 '08 #4
Thank you so much!
Yes you were right, it just wasn't declaring it as an array!

The random array values I was displaying were just so I could check I was using the array properly when reading into it from the database.

Again, thank you
Mar 31 '08 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

14
by: Dave | last post by:
Hello all, Can anybody help with the problem below? I'm trying to define a conversion function that converts objects to function pointers and am getting a compile error on the line indicated...
1
by: Matthias De Ridder | last post by:
Hello, I really hope that someone will be able to help me, because I'm desperate now! I'm a student, graduating this year, and I'm working on a thesis where C# Web Services are involved. I...
11
by: Steve Smith | last post by:
I have written a winforms application that launches approximately 150 threads with Thread.ThreadStart() Each thread uses CDO 1.21 to logon to a different Exchange mailbox and send/receive a...
2
by: David R | last post by:
Can someone tell me what I am doing wrong here? This will not compile because of line 2, but if I replace with Service.ContactTO contacts = null; it will through an exception on line 3. Thanks...
15
by: Joseph Geretz | last post by:
I'm a bit puzzled by the current recommendation not to send Datasets or Datatables between application tiers. http://support.microsoft.com/kb/306134 ...
1
by: Alan Sloan | last post by:
I have written a Web Service that interacts with a COM component to extract a file from another system. Basically the Web Service accepts a part number and a rev and extracts the file to a...
3
by: Peter Oliphant | last post by:
Below are the definitions of two classes. VList creates two static integer arrays (v_0, v_1), creates an array of pointers to these arrays (vlist), and has a public method to return a pointer to...
2
by: =?Utf-8?B?RHJldw==?= | last post by:
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...
0
ntxsoft
by: ntxsoft | last post by:
Hello everybody, I have a small problem while returning array from web service. Firstly I'm new at java web services and I'm using netbeans 6 with glassfish 2. The problem is I have a class, name is...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.