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 432633
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T20:05:38+00:00 2026-05-12T20:05:38+00:00

I made a WPF example that consumes a web service ( www.webservicex.com/globalweather.asmx ) in

  • 0

I made a WPF example that consumes a web service (http://www.webservicex.com/globalweather.asmx) in two different ways:

with events like this:

public Window1()
{
    InitializeComponent();
    DataContext = this;

    Location = "loading...";
    Temperature = "loading...";
    RelativeHumidity = "loading...";

    client.GetWeatherCompleted += 
            new EventHandler<GetWeatherCompletedEventArgs>(client_GetWeatherCompleted);
    client.GetWeatherAsync("Berlin", "Germany");
}

void client_GetWeatherCompleted(object sender, GetWeatherCompletedEventArgs e)
{
    XDocument xdoc = XDocument.Parse(e.Result);

    Location = xdoc.Descendants("Location").Single().Value;
    Temperature = xdoc.Descendants("Temperature").Single().Value;
    RelativeHumidity = xdoc.Descendants("RelativeHumidity").Single().Value;
}

and with the Begin/End methods and IAsyncResult like this:

public Window1()
{
    InitializeComponent();
    DataContext = this;

    Location = "loading...";
    Temperature = "loading...";
    RelativeHumidity = "loading...";

    client.BeginGetWeather("Berlin", "Germany", new AsyncCallback(GotWeather), null);
}

void GotWeather(IAsyncResult result)
{
    string xml = client.EndGetWeather(result).ToString();
    XDocument xdoc = XDocument.Parse(xml);

    Location = xdoc.Descendants("Location").Single().Value;
    Temperature = xdoc.Descendants("Temperature").Single().Value;
    RelativeHumidity = xdoc.Descendants("RelativeHumidity").Single().Value;

}

These two approaches seem to perform the exact same task.

What are their advantages and disadvantages? When would you use one and not the other?

  • 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-12T20:05:38+00:00Added an answer on May 12, 2026 at 8:05 pm

    For the case of remote services, I usually prefer to use callbacks instead of event handlers since it leads to more readable/maintainable code (by just looking at the service call invokation code I know which code will be executed when the call finishes). Moreover when using event handlers you need to have care for not declaring them more than once.

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

Sidebar

Related Questions

I made a WPF app that uses Web Services. It is failing on all
Currently i have made a bar chart from a listbox from this example: http://weblogs.thinktecture.com/cnagel/2011/06/wpf-listbox-as-bar-chart.html
I'm a complete beginner at WPF. I've made a usercontrol labeledTextbox that holds a
I was looking this site for data validation: http://codeblitz.wordpress.com/2009/05/08/wpf-validation-made-easy-with-idataerrorinfo/ And it sounds great the
I made an WPF app that plays sounds using the MediaPlayer class. This works
I have a WPF window that goes fullscreen, and I have made every attempt
I am building a WPF application that calls web services and displays the data
I have a few user controls I made in wpf that are driven by
I have a WPF application that is made up of a window containing a
I made a WPF application that opens the CSV file and does some operation

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.