Ejemplo n.º 1
0
        private async void GetWeather()
        {
            try
            {
                string city   = cbCities.Items[cbCities.SelectedIndex].ToString();
                string result = await client.GetWhetherInfoSerializedAsync(city);

                WcfServiceClient.ServiceReference1.WheatherInfo weatherInfo;
                using (Stream stream = new MemoryStream())
                {
                    byte[] data = System.Text.Encoding.UTF8.GetBytes(result);

                    stream.Write(data, 0, data.Length);
                    stream.Position = 0;

                    var dataContractSerializer = new DataContractSerializer(typeof(WcfServiceClient.ServiceReference1.WheatherInfo));

                    weatherInfo = (WcfServiceClient.ServiceReference1.WheatherInfo)dataContractSerializer.ReadObject(stream);
                }
                lbTemperature.Text = "Сейчас: " + weatherInfo.temperature;
                lbSpeed.Text       = weatherInfo.speed;
                lbHumadity.Text    = weatherInfo.humadity;
                lbPressure.Text    = weatherInfo.pressure;
                lbTime.Text        = string.Format("Время обновления: {0}", DateTime.Now.ToString("HH:mm:ss"));
            }
            catch (Exception ex)
            {
                timer.Stop();
                MessageBox.Show(ex.Message);
            }
        }