Windows Phoneアプリケーションの作成
今回作成するアプリケーションは最初の画面にカードを引くボタンが配置されていて,
MainPage. xaml
MainPage.
次に,
プロパティパネルで
MainPage. xaml. cs
MainPage.
private void DrawButton_Click(object sender, RoutedEventArgs e)
{
this.NavigationService.Navigate(new Uri("/ResultPage.xaml", UriKind.Relative));
}
Windows Phoneでは画面の遷移処理はNavigationServiceを用いて行います。Navigateメソッドを用いると指定したURIの画面に遷移します。今回は画面遷移する際のトランジション等は指定していませんが,
ResultPage. xaml
カードを引いた結果を表示する画面としてResultPage.
デザインビューで画面の項目の設定を修正していきます。
次に,
<TextBlock Height="36" HorizontalAlignment="Center" Margin="0,20,0,0"
Name="NameTextBlock" Text="TextBlock" VerticalAlignment="Top"
Width="196" TextAlignment="Center" />
<Image Height="338" HorizontalAlignment="Left" Margin="0" Name="CardImage"
Stretch="Fill" VerticalAlignment="Center" Width="450" />
ResultPage. xaml. cs
ResultPage.
Windows Azure上のアプリケーションへのリクエストは今回はWebClientを用いたオーソドックスな形で行います
カードを引く処理は下記のようになります。
protected override void OnNavigatedTo(NavigationEventArgs e)
{
base.OnNavigatedTo(e);
WebClient webClient = new WebClient();
webClient.Headers[HttpRequestHeader.IfModifiedSince] = "Thu, 01 Jun 1970 00:00:00 GMT";
Uri uri = new Uri("http://127.0.0.1:81/GameService/getcard");
webClient.DownloadStringCompleted +=
new DownloadStringCompletedEventHandler(webClient_DownloadStringCompleted);
webClient.DownloadStringAsync(uri);
}
リクエストのヘッダにIfModifiedSinceを設定する事により,
次に,
最初にアセンブリへの参照を2つ追加します。プロジェクトの参照設定を右クリックして,
最初にGameWebRole.
次に,
- Json.
NET
http://json. codeplex. com/
それではGameWebRoleへの通信のレスポンスを受け取る処理の中身を書いて行きます。
protected override void OnNavigatedTo(NavigationEventArgs e)
{
base.OnNavigatedTo(e);
WebClient webClient = new WebClient();
webClient.Headers[HttpRequestHeader.IfModifiedSince] = "Thu, 01 Jun 1970 00:00:00 GMT";
Uri uri = new Uri("http://127.0.0.1:81/GameService/getcard");
webClient.DownloadStringCompleted +=
new DownloadStringCompletedEventHandler(webClient_DownloadStringCompleted);
webClient.DownloadStringAsync(uri);
}
処理の流れとしては,
一通りの実装が終わりましたので,
今回作成したサンプルはこちらです。
最後に
今回はWindows Phoneアプリケーションを作成して,