Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3233540
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T17:17:19+00:00 2026-05-17T17:17:19+00:00

I have a webservice that calls a method and returns a generic list. The

  • 0

I have a webservice that calls a method and returns a generic list. The webservice completed method looks like this (note: names and e.Result are both of the same type of List):

   void SetNames()
   {    
        ServiceReference1.ServiceClient webservice = new ServiceReference1.ServiceClient();

        webservice.GetNameCompleted += new EventHandler<GetNameCompletedEventArgs>(webservice_GetNameCompleted);
        webservice.GetNameAsync();
    }
    private void webservice_GetNameCompleted(object sender, ServiceReference1.GetNameCompletedEventArgs e)
    {
       names = e.Result;     
    }

The problem I’m having is that I can only retrieve the items in the names list in the webservice method. Whenever I try to access the items in the names list anywhere outside of that method it is empty. For example (this displays nothing in the textbox),

List<string> names = new List<string>();

public MainPage()
{
    InitializeComponent();
    SetNames();

    foreach (string name in names)
        textBox1.Text += name;
 }

But this will display the correct thing:

private void webservice_GetNameCompleted(object sender, ServiceReference1.GetNameCompletedEventArgs e)
    {
       names = e.Result;

       foreach (string name in names)
          textBox1.Text += name;     
    }

I’m new to Silverlight and webservies, and I’m probably over looking something. I’ve been working on this for a while and I’m at the point where I feel I need to ask for help. Any help would be greatly appreciated!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-17T17:17:20+00:00Added an answer on May 17, 2026 at 5:17 pm

    In Silverlight all calls to web-services are asynchronous (unlike WPF which can also use synchronous call).

    It means that the code after the call to the web-service will be invoked before the service has sent a response to the Silverlight client.

    So, in the MainPage constructor, the foreach loop is iterating over the collection BEFORE the service has returned, and then iterate over an empty collection.

    The right way to proceed is the second one : initializing the collection after the service has responded, in the callback method dedicated to this task : webservice_GetNameCompleted.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a webservice that calls a method that returns a generic list of
I have an ASP.NET webservice method that returns a generics list (List'<'Construct>) serialized as
I have created a console application that calls a method on a webservice. I
We have some really old code that calls WebServices using behaviours (webservice.htc), and we
I am developing an Windows phone7 application, I have a .NET webservice that returns
I have a webservice which returns the content of a pdf. I've noticed that
In my MVC 2 application I have a typical method that calls a web
I know this has been addressed before but I have service that returns a
I have a simple web service method that returns a simple java class as
We have a legacy WSE3 ASP.Net webservice here that defines a method GetFileContent(string fileName)

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.