成人免费xxxxx在线视频软件_久久精品久久久_亚洲国产精品久久久_天天色天天色_亚洲人成一区_欧美一级欧美三级在线观看

Windows Phone開(kāi)發(fā)(47):輕松調(diào)用Web Service

移動(dòng)開(kāi)發(fā)
移動(dòng)設(shè)備現(xiàn)在緊密的跟互聯(lián)網(wǎng)結(jié)合,開(kāi)發(fā)者應(yīng)該利用這個(gè)優(yōu)勢(shì)來(lái)開(kāi)發(fā)各種網(wǎng)絡(luò)服務(wù),今天我們介紹在 Windows Phone 上開(kāi)發(fā) Web 服務(wù)應(yīng)用。

眾所周知(除了沒(méi)用過(guò)VS的),在VS里面調(diào)用Web Service是一件很愉快的事情,不解釋,相信很多朋友在以前的項(xiàng)目中肯定也用過(guò)WEB服務(wù)。同樣,在WP中調(diào)用Web Service也是非常簡(jiǎn)單的,你可以不信,反正我絕對(duì)信了。

有例子有真相,我們就以http://webservice.webxml.com.cn/WebServices/IpAddressSearchWebService.asmx

為例,這個(gè)Web服務(wù)可以根據(jù)IP地址查詢相關(guān)的地區(qū)/城市信息,我們就通過(guò)調(diào)用這WEB服務(wù),來(lái)比較一下,在WP項(xiàng)目調(diào)用Web Service與我們以前做過(guò)的其它類型到底有沒(méi)有區(qū)別。

1、啟動(dòng)VS,新建一個(gè)WP應(yīng)用程序項(xiàng)目(此處省略46個(gè)字)。

2、頁(yè)面布局就參考下面XAML吧。

  1. <phone:PhoneApplicationPage    
  2.     x:Class="MyApp.MainPage"   
  3.     xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"   
  4.     xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"   
  5.     xmlns:phone="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone"   
  6.     xmlns:shell="clr-namespace:Microsoft.Phone.Shell;assembly=Microsoft.Phone"   
  7.     xmlns:d="http://schemas.microsoft.com/expression/blend/2008"   
  8.     xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"   
  9.     mc:Ignorable="d" d:DesignWidth="480" d:DesignHeight="768"   
  10.     FontFamily="{StaticResource PhoneFontFamilyNormal}"   
  11.     FontSize="{StaticResource PhoneFontSizeNormal}"   
  12.     Foreground="{StaticResource PhoneForegroundBrush}"   
  13.     SupportedOrientations="Portrait" Orientation="Portrait"   
  14.     shell:SystemTray.IsVisible="True">   
  15.     <!--LayoutRoot 是包含所有頁(yè)面內(nèi)容的根網(wǎng)格-->   
  16.     <Grid x:Name="LayoutRoot" Background="Transparent">   
  17.         <Grid.RowDefinitions>   
  18.             <RowDefinition Height="Auto"/>   
  19.             <RowDefinition Height="*"/>   
  20.         </Grid.RowDefinitions>   
  21.         <!--TitlePanel 包含應(yīng)用程序的名稱和頁(yè)標(biāo)題-->   
  22.         <StackPanel x:Name="TitlePanel" Grid.Row="0" Margin="12,17,0,28">   
  23.             <TextBlock x:Name="ApplicationTitle" Text="我的應(yīng)用程序" Style="{StaticResource PhoneTextNormalStyle}"/>   
  24.             <TextBlock x:Name="PageTitle" Text="頁(yè)面名稱" Margin="9,-7,0,0" Style="{StaticResource PhoneTextTitle1Style}"/>   
  25.         </StackPanel>   
  26.         <!--ContentPanel - 在此處放置其他內(nèi)容-->   
  27.         <Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0">   
  28.             <Grid.RowDefinitions>   
  29.                 <RowDefinition Height="auto"/>   
  30.                 <RowDefinition Height="*"/>   
  31.             </Grid.RowDefinitions>   
  32.             <Grid Grid.Row="0">   
  33.                 <Grid.ColumnDefinitions>   
  34.                     <ColumnDefinition Width="auto"/>   
  35.                     <ColumnDefinition Width="*"/>   
  36.                     <ColumnDefinition Width="auto"/>   
  37.                 </Grid.ColumnDefinitions>   
  38.                 <TextBlock Grid.Column="0" VerticalAlignment="Center" Text="IP地址:"/>   
  39.                 <TextBox Name="txtIP" Grid.Column="1"/>   
  40.                 <Button Grid.Column="2" Click="onQuery">   
  41.                     <Button.Content>   
  42.                         <Path Data="M0,10 L20,10 M5,0 L20,10 M5,20 L20,10"   
  43.                               VerticalAlignment="Stretch"   
  44.                               HorizontalAlignment="Stretch"   
  45.                               Stroke="White" StrokeThickness="3"/>   
  46.                     </Button.Content>   
  47.                 </Button>   
  48.             </Grid>   
  49.             <StackPanel Grid.Row="1">   
  50.                 <TextBlock Name="txbTip"/>   
  51.                 <TextBlock Name="txbResult" Margin="2,12,2,0" FontSize="32"/>   
  52.             </StackPanel>   
  53.         </Grid>   
  54.     </Grid>   
  55. </phone:PhoneApplicationPage> 

3、打開(kāi)“解決方案資源管理器”,右擊“引用”節(jié)點(diǎn),從彈出的菜單中選擇“添加服務(wù)引用”。

4、在彈出的對(duì)話框中,“地址”處輸入上文中提到的Web服務(wù)的地址,并點(diǎn)擊“前往”按鈕,待發(fā)現(xiàn)WEB服務(wù)完成后,在“命名空間”處輸入一個(gè)有效命名空間名字,隨你喜歡。***別忘了單擊“確定”。

5、切換到后臺(tái)代碼,完成查詢按鈕的單擊事件處理。

  1. private void onQuery(object sender, RoutedEventArgs e)   
  2. {   
  3.     // ***步,實(shí)例化客戶端代理類   
  4.     IPQueryWebService.IpAddressSearchWebServiceSoapClient MyClient = new IPQueryWebService.IpAddressSearchWebServiceSoapClient();   
  5.     // 第二步,綁定回調(diào)事件   
  6.     MyClient.getCountryCityByIpCompleted += (s, arg) =>   
  7.         {   
  8.             // 取得結(jié)果   
  9.             txbTip.Text = "請(qǐng)求完成。";   
  10.             if (arg.Error != null)   
  11.             {   
  12.                 txtIP.Text = string.Format("錯(cuò)誤:{0}", arg.Error.Message);   
  13.                 return;   
  14.             }   
  15.             string[] res = arg.Result;   
  16.             if (res != null)   
  17.             {   
  18.                 if (res.Length > 1)   
  19.                 {   
  20.                     txbResult.Text = string.Format("查詢結(jié)果:{0}", res[1]);   
  21.                 }   
  22.             }   
  23.         };   
  24.     // 第三步,調(diào)用異步方法   
  25.     txbTip.Text = "正在請(qǐng)求,請(qǐng)等候……";   
  26.     MyClient.getCountryCityByIpAsync(txtIP.Text);   

好了,完成,記住WEB服務(wù)一般是異步調(diào)用,所以要在回調(diào)事件處理中取得調(diào)用結(jié)果。

運(yùn)行一下,看看結(jié)果吧。

OK,就到這里吧。

責(zé)任編輯:閆佳明 來(lái)源: Windows Phone
相關(guān)推薦

2013-07-30 12:37:56

Windows PhoWindows Pho

2010-04-21 17:07:54

Windows Pho

2013-04-17 14:00:06

Windows PhoWindows Pho

2011-06-07 12:42:15

Windows Pho

2013-04-16 17:02:50

Windows Pho概論

2013-04-19 16:34:56

Windows PhoWindows Pho

2013-07-30 11:18:37

Windows PhoWindows Pho

2010-04-08 17:40:23

Windows Pho

2010-07-16 15:29:02

Windows Pho

2011-06-07 11:35:38

Windows Pho

2013-04-17 13:27:04

Windows PhoWindows Pho

2013-07-31 13:03:51

Windows PhoWindows Pho

2013-04-17 14:47:19

Windows PhoWindows Pho

2012-08-16 10:35:50

Windows Pho

2013-04-19 16:52:24

Windows PhoWindows Pho

2013-07-31 12:50:39

搭建Windows PWindows Pho

2013-07-31 13:13:50

Windows PhoMVVM模式

2010-12-14 18:48:49

微軟

2012-06-04 14:47:58

Windows Pho

2013-04-19 15:35:54

Windows Pho隔離存儲(chǔ)
點(diǎn)贊
收藏

51CTO技術(shù)棧公眾號(hào)

主站蜘蛛池模板: 国产一区二区在线视频 | 91亚洲国产成人精品一区二三 | 激情欧美一区二区三区中文字幕 | 欧美毛片免费观看 | 91传媒在线观看 | 天堂亚洲网 | 中文字幕免费在线 | 亚洲最大看片网站 | 97成人免费| 一区二区三区欧美在线 | 亚洲高清免费视频 | 亚洲国产成人av好男人在线观看 | 欧美一区二区三区在线播放 | 狠狠久| 亚洲国产精品第一区二区 | 自拍偷拍小视频 | 国产一级毛片视频 | 91视在线国内在线播放酒店 | 亚洲欧美一区二区三区国产精品 | 国产三级网站 | 久久99网| 美女视频一区二区 | 69亚洲精品 | 国产精品亚洲片在线播放 | 国产精品视频在线播放 | 超碰在线亚洲 | 亚洲一区二区三区四区视频 | 国产日韩欧美 | 自拍视频网 | 国产精品99一区二区 | 亚洲国产精品久久久久婷婷老年 | 大香在线伊779 | 亚洲成人免费视频在线观看 | 99久久99热这里只有精品 | 国产精品国产精品国产专区不蜜 | 免费视频久久久久 | 天天曰天天曰 | 精品国产鲁一鲁一区二区张丽 | 狠狠久| 精品国产乱码久久久久久影片 | 欧美乱操 |