Skip to main content

Microsoft Silverlight

Answered Question Web Service Method Returns an ArrayRSS Feed

(0)

stevenjamesfrank65
stevenja...

Member

Member

38 points

111 Posts

Web Service Method Returns an Array

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
bryant

Star

Star

9937 points

1,629 Posts

Silverlight MVP

Re: Web Service Method Returns an Array

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.

-- bryant

Blog | Twitter
_________________
Dont forget to click "Mark as Answer" on the post that helped you.

stevenjamesfrank65
stevenja...

Member

Member

38 points

111 Posts

Re: Web Service Method Returns an Array

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 = ForcastDevil;
            }
        }
The object names canForcastx are Canvas controls that hold a few other controls that will bind to specific fields.  The type ArrayOfAnyType is what this method returns.

bryant
bryant

Star

Star

9937 points

1,629 Posts

Silverlight MVP
Answered Question

Re: Web Service Method Returns an Array

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.

-- bryant

Blog | Twitter
_________________
Dont forget to click "Mark as Answer" on the post that helped you.
  • Unanswered Question
  • Answered Question
  • Announcement
Microsoft Communities