WPF调用WebService实现天气预报
发布时间:2020-12-16 23:55:36 所属栏目:安全 来源:网络整理
导读:之前经常听同事说起WebService这个东西,今天认真看了看查到一篇关于“Winform调用WebService实现天气预报”的文章。 wpf与Winform几乎一样。都是调用互联网上公开的WebServices( http://www.webxml.com.cn/WebServices/WeatherWebService.asmx )来实现天气
之前经常听同事说起WebService这个东西,今天认真看了看查到一篇关于“Winform调用WebService实现天气预报”的文章。 <Window x:Class="Wpf调用webservices.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Title="WPF调用WebService实现天气预报" Height="404" Width="662"> <Grid> <Label Content="输入城市名称:" Height="29" HorizontalAlignment="Left" Margin="12,12,0" Name="label1" VerticalAlignment="Top" Width="108" /> <Label Content="显示天气" Height="29" HorizontalAlignment="Left" Margin="94,91,0" Name="label3" VerticalAlignment="Top" Width="209" /> <Label Content="天气概况:" Height="29" HorizontalAlignment="Left" Margin="12,0" Name="label4" VerticalAlignment="Top" Width="76" /> <Label Content="天气实况:" Height="29" HorizontalAlignment="Left" Margin="12,164,0" Name="label5" VerticalAlignment="Top" Width="76" /> <TextBox Height="29" HorizontalAlignment="Left" Margin="139,0" Name="textBox1" VerticalAlignment="Top" Width="81" /> <Button Content="查询" Height="28" HorizontalAlignment="Left" Margin="228,13,0" Name="button1" VerticalAlignment="Top" Width="48" Click="button1_Click" /> <Image Height="29" HorizontalAlignment="Right" Margin="0,364,0" Name="image1" Stretch="Fill" VerticalAlignment="Top" Width="33" Source="/Wpf调用webservices;component/bin/Debug/image/1.gif" /> <TextBox Height="71" HorizontalAlignment="Left" Margin="94,130" Name="textBox2" VerticalAlignment="Bottom" Width="363" TextWrapping="Wrap" /> </Grid> </Window> private void button1_Click(object sender,RoutedEventArgs e) { Weather.WeatherWebServiceSoapClient w = new Weather.WeatherWebServiceSoapClient("WeatherWebServiceSoap"); string[] s = new string[23];//声明string数组存放返回结果 string city = this.textBox1.Text.Trim();//获得文本框录入的查询城市 s = w.getWeatherbyCityName(city); if (s[8] == "") { MessageBox.Show("输入错误,请重新输入","提示",MessageBoxButton.OK,MessageBoxImage.Information); } else { this.label3.Content = s[1] + " " + s[6]; textBox2.Text = s[10]; } } (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |