之前经常听同事说起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]; } }
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。