The asynchronous search problem

The following is my code
weatherForcast.cs
  class weatherForcast
{
private WeatherWSSoapClient client;
private string cityName;
private string weatherResult;
public weatherForcast(string cn)
{
client = new WeatherWSSoapClient();
client.getWeatherCompleted += new EventHandler<getWeatherCompletedEventArgs>(client_getWeatherCompleted);
cityName = cn;
weatherResult = "";
}

public string getWeather()
{

client.getWeatherAsync(cityName, "");
return weatherResult;
}

public void client_getWeatherCompleted(object sender, getWeatherCompletedEventArgs e)
{

string[] result = e.Result;
if (result.Length <1)
{
weatherResult = "Not here weather information";
}
else
{
StringBuilder sb = new StringBuilder();
sb.Append(result[1] + "\n");//City name
sb.Append(result[4] + "\n");//Today the weather
sb.Append(result[5] + "\n\n");//Air quality, UV intensity

sb.Append("Today "+ result[7] +" \n "); // date, weather conditions
sb.Append(result[8] + "\n");//Air temperature
sb.Append(result[9] + "\n\n");//Wind direction, wind speed

//sb.Append("Tomorrow" + result[12] + "\n");
//sb.Append(result[13] + "\n");
//sb.Append(result[14] + "\n\n");

//sb.Append("The day after tomorrow" + result[17] + "\n");
//sb.Append(result[18] + "\n");
//sb.Append(result[19] + "\n\n");
weatherResult = sb.ToString();

}
}
}

Then I call the MainPage.xaml.cs as follows
 weatherForcast wf = new weatherForcast("Wuhan");
string weather = wf.getWeather();

Why the weather is empty.?
I found this event registration in debugging client_getWeatherCompleted (object sender, getWeatherCompletedEventArgs E) were never call don't know why? ? ?

Started by Liz at December 03, 2016 - 12:44 AM

GetWeatherAsync how to write?

Posted by Ira at December 15, 2016 - 12:53 AM

GetWeatherAsync is a WeatherWSSoapClient method, quoted from the server

Posted by Liz at December 30, 2016 - 1:26 AM

GetWeatherAsync has gone to another thread inside, how can you guarantee that what time he returns?

Posted by Ira at January 05, 2017 - 1:34 AM

How to solve it?

Posted by Liz at January 08, 2017 - 1:36 AM