void background_DoWork(object sender, DoWorkEventArgs e) { using (WeatherService.WeatherWebServiceSoapClient wwsc = new WeatherService.WeatherWebServiceSoapClient()) { e.Result = wwsc.getWeatherbyCityName("周口");//进行方法调用,并将返回值存放到事件中的Result进行传递 } }
protected void Button1_Click(object sender, EventArgs e) { using (WeatherService.WeatherWebServiceSoapClient wwsc = new WeatherService.WeatherWebServiceSoapClient())//创建客户单代理类 { wwsc.getWeatherbyCityNameAsync("周口");//进行异步调用 wwsc.getWeatherbyCityNameCompleted += new EventHandler<WeatherService.getWeatherbyCityNameCompletedEventArgs>(wwsc_getWeatherbyCityNameCompleted); } }
/// <summary> /// 加载今日阴历、阳历、天气信息 /// </summary> private void initTodayInfo() { CNDate cnDate = new CNDate(DateTime.Now); today_label1.Text = cnDate.GetDateAsShort() + " " + cnDate.GetDayOfWeek(); today_label2.Text = DateTime.Now.Day.ToString(); today_label3.Text = cnDate.GetLunarHolDay(); today_label4.Text = cnDate.FormatLunarYear(); WeatherService.WeatherWebServiceSoapClient wwsc = new WeatherService.WeatherWebServiceSoapClient(); string[] weathers = wwsc.getWeatherbyCityName("石家庄"); today_weather_label.Text = weathers[6]; today_weather_label1.Text = weathers[5]; today_weather_label2.Text = weathers[7]; tomorrow_weather_label.Text = weathers[13]; tomorrow_weather_label1.Text = weathers[12]; tomorrow_weather_label2.Text = weathers[14]; tomorrow2_weather_label.Text = weathers[18]; tomorrow2_weather_label1.Text = weathers[17]; tomorrow2_weather_label2.Text = weathers[19]; today_weather_pictureBox1.BackgroundImage = new Bitmap(Application.StartupPath.ToString() + "\\Weather\\" + weathers[8]); today_weather_pictureBox2.BackgroundImage = new Bitmap(Application.StartupPath.ToString() + "\\Weather\\" + weathers[9]); tomorrow_weather_pictureBox1.BackgroundImage = new Bitmap(Application.StartupPath.ToString() + "\\Weather\\" + weathers[15]); tomorrow_weather_pictureBox2.BackgroundImage = new Bitmap(Application.StartupPath.ToString() + "\\Weather\\" + weathers[16]); tomorrow2_weather_pictureBox1.BackgroundImage = new Bitmap(Application.StartupPath.ToString() + "\\Weather\\" + weathers[20]); tomorrow2_weather_pictureBox2.BackgroundImage = new Bitmap(Application.StartupPath.ToString() + "\\Weather\\" + weathers[21]); }
public WeatherViewModel GetWeatherInfo(string IpAddress) { WeatherViewModel weatherViewModel = null; IPLocationService IPLocationService = new IPLocationService(); string cityName = IPLocationService.getCity(IpAddress); if (string.IsNullOrEmpty(cityName)) { cityName = "深圳"; } try { WeatherService.WeatherWebServiceSoapClient aService = new WeatherService.WeatherWebServiceSoapClient(); if (cityName.Contains("市")) { cityName = cityName.Substring(0, cityName.Length - 1); } string[] wa = aService.getWeatherbyCityName(cityName); if (!string.IsNullOrEmpty(wa[1])) { weatherViewModel = new WeatherViewModel(); weatherViewModel.cityName = wa[1]; weatherViewModel.airTemperature = wa[5]; weatherViewModel.meteorological = wa[6]; return weatherViewModel; } else { return weatherViewModel; } } catch (Exception ex) { Logger.Error("GetWeatherInfo" + ex.Message, ex); return null; } }