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

  • SEARCH
  • Home
  • 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 6071675
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T10:04:28+00:00 2026-05-23T10:04:28+00:00

I’m beginner with C# and wp7 platform and I have some problem with good

  • 0

I’m beginner with C# and wp7 platform and I have some problem with good idea to get request from web service.

I made webservice in PHP (nusoap – WSDL) and everything is working fine in “normal” using.
Now I have ObservableCollection saved in IsolatedStorage with I load when Page is open (List of watched stacks exchange). Then I want to refresh data for every item from web service.

I don’t know whether this is a good idea.

Code:

private GPWWebservicePortTypeClient client = new GPWWebservicePortTypeClient();
private ObservableCollection<WebServiceClass.ItemGetValues> StoredStock = 
                      new ObservableCollection<WebServiceClass.ItemGetValues>();     
public const string _fileName = "listaObserwowanych.xml";
public Page()
{
   InitializeComponent();

   DataContext = App.ViewModel;

   this.Loaded += new RoutedEventHandler(Page_Loaded);

   client.GetLastValueCompleted +=
            new EventHandler<GetLastValueCompletedEventArgs>(client_GetLastValueCompleted);

   foreach (var itemGetValuese in App.ViewModel.Items)
   {
      client.GetLastValueAsync(itemGetValuese.name);
   }

   var o = 
       Observable.FromEvent<GetLastValueCompletedEventArgs(client,"GetLastValueCompleted")
                                                           .Subscribe(setList);
}

void client_GetLastValueCompleted(object sender, GetLastValueCompletedEventArgs e)
{
    if (e.Error != null)
    {
        MessageBox.Show(Convert.ToString(e.Error));
    }
    else
    {
        ObservableCollection<WebServiceClass.ItemGetValues> ListValues = 
          (ObservableCollection<WebServiceClass.ItemGetValues>)                                                                      
           JsonConvert.DeserializeObject(e.Result, 
           typeof(ObservableCollection<WebServiceClass.ItemGetValues>));
        StoredStock.Add(ListValues[0]);
    }
}

private void setList(IEvent<GetLastValueCompletedEventArgs> ex)
{
    List.ItemsSource = StoredStock;
}


void Page_Loaded(object sender, RoutedEventArgs e)
{
    App.ViewModel.LoadData();
    List.ItemsSource = App.ViewModel.Items;
}

Like u see I use RX to call method client_GetLastValueCompleted add store result to auxiliary variable (StoredStock). Then refresh List in setList method, but that method is client_GetLastValueCompleted what is not soo good idea, becouse I need to run that method only when all of runned GetLastValueAsync in foreach is completed.
Second problem: becouse of async web service method StoredStock sometime have different order than App.ViewModel.Items .

Any good idea how to do that in right way?
Best regards,

Lukas

  • 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-23T10:04:28+00:00Added an answer on May 23, 2026 at 10:04 am

    You’re really mixing up a number of ways to call web services and Rx. You really need to decide on a single way and stick to it.

    If you’re going to use Rx, then you’ll have something like this:

    public Page()
    {
        InitializeComponent();
    
        DataContext = App.ViewModel;
    
        this.Loaded += new RoutedEventHandler(Page_Loaded);
    }
    
    void Page_Loaded(object sender, RoutedEventArgs e)
    {
        App.ViewModel.LoadData();
    
        var storedStock =
            new ObservableCollection<WebServiceClass.ItemGetValues>();  
    
        List.ItemsSource = storedStock;
    
        var values =
            Observable.Using<WebServiceClass.ItemGetValues, GPWWebservicePortTypeClient>
                (() => new GPWWebservicePortTypeClient(), ws =>
                {
                    var clientGetLastValue = Observable
                        .FromAsyncPattern<string, GetLastValueResponse>
                        (ws.BeginGetLastValue, ws.EndGetLastValue);
    
                    Func<string, WebServiceClass.ItemGetValues> deserializeFirst = r =>
                        ((List<WebServiceClass.ItemGetValues>)JsonConvert
                        .DeserializeObject(r,
                            typeof(List<WebServiceClass.ItemGetValues>)))
                        .First();
    
                    return
                        from item in App.ViewModel.Items
                        from e in clientGetLastValue(item)
                        select deserializeFirst(e.Result);
                });
    
        values.Subscribe(storedStock.Add);
    }
    

    You’ll have to get the right method call names for your web service client, but the code should roughly be right. Let me know how you go.


    I corrected the code above. Should have returned the query inside the Using call rather than assign it to values.


    I corrected the call to FromAsyncPattern to use the correct method names and return type from the actual web service reference class sent via email.

    It should look like this:

    Observable.FromAsyncPattern<string, GetLastValueResponse>
        (ws.BeginGetLastValue, ws.EndGetLastValue);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have just tried to save a simple *.rtf file with some websites and
For some reason, after submitting a string like this Jack’s Spindle from a text
I am currently running into a problem where an element is coming back from
I have a text area in my form which accepts all possible characters from
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have a bunch of posts stored in text files formatted in yaml/textile (from
I have some data like this: 1 2 3 4 5 9 2 6
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have a jquery bug and I've been looking for hours now, I can't

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.