Skip to main content
Home Forums Silverlight Programming Accessing Web Services with Silverlight Web Service Method Returns an Array
3 replies. Latest Post by bryant on March 9, 2009.
(0)
stevenja...
Member
38 points
111 Posts
03-09-2009 2:19 PM |
I have a SL app that is getting data from a web service.
So far, the methods I've been using return a single object and I have been doing things like this:
myGrid.DataContext = e.Result; or myTextBlock.DataContext = e.Result.someField;
All of this works fine. I'm now using another method of the same service, but this one returns an array and I'm having trouble with the syntax for referencing the elements. I've tried the follwoing (and other variations with no success):
myGrid.DataContext = e.Result[x]; // where x is the index
Also, I've noticed that there are no fields listed by IntelliSense on e.Result or e.Result[x]
What am I missing?
bryant
Star
9937 points
1,629 Posts
03-09-2009 2:34 PM |
I'm guessing that e.Result is of type object? Hard to say without seeing more of the code.
Are you trying to bind the data context to a specific item in the array? If so you'll probably need to case the e.Result to an array of the correct type.
var array = e.Result as sometype[];
if (array != null) myGrid.DataContext = array[x];
Anyhow, if this doesn't answer try posting a snippet of your code.
03-09-2009 3:07 PM |
Here is my latest attempt. It compiles but I get an error at run time (although with the web service, it is impossible to get any formal debugging info back at run time so I have no idea what the complaint is).
void proxy_GetForecastByUSZipCodeCompleted(object sender, GetForecastByUSZipCodeCompletedEventArgs e) { if (e.Error == null & e.Result != null) { ArrayOfAnyType Forcast = e.Result; canForecast0.DataContext = Forcast[0]; //canForecast1.DataContext = Forcast[1]; //canForecast2.DataContext = Forcast[2]; //canForecast3.DataContext = Forcast[3]; //canForecast4.DataContext = Forcast[4]; //canForecast5.DataContext = Forcast[5]; //canForecast6.DataContext = Forcast; } }
03-09-2009 4:39 PM |
Are you getting a result back or are you getting an error when you call the server?
You can attach the debugger to internet explorer and step through the code to see what you're getting back.