简体   繁体   中英

Consume Webservice in Silverlight Application

Step 1: I assigned the value for id is zero.

step 2: I tried to update the Id value by service return.But it was not updated Immediately.

step 3: so the _objsomeClass.SetId= id; value Set as zero. Here I need the Service return value to assign for _objsomeClass.SetId

step 4: After the For loop executed then the value _objsomeClass.SetId= id; assigned from Webservice return Value.

I need to set the value which is return from webservice before the for loop execution?

public void Save_Click(object sender, RoutedEventArgs e)
{
    int id= 0;
    Service.Client Clientobj = new ChatACDService.ChatACDServiceClient();

    Clientobj .GetIdCompleted += (s, ev) =>
    {
        id = ev.Result;
    };

    Clientobj .GetIdAsync();     

    _objsomeClass.SetId= id;

    for (int i = 0; i < Agent.Items.Count; i++)
    {
        //Some Process
    }
}

If I'm reading your question right I think I see your problem. The issue is that the GetIdAsync method you are calling does not block the code execution as the name suggests. What you need to do is move that loop into the GetIdCompleted block so it runs after the web service call is over.

There are other ways of managing async returns, my personal favourite is the Rx Framework, its great for chaining async calls together, check it out https://msdn.microsoft.com/en-us/data/gg577609.aspx

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM