データを更新した後、Web サービスが呼び出されると、まだ古いデータがフェッチされます。アプリからログアウトしてから再度ログインしたときにのみ、新しいデータが読み込まれます。
protected async override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e)
{
base.OnNavigatedTo(e);
parameterValue = this.NavigationContext.QueryString["parameter"];
Uri UserDetailUrl = new Uri(Constants.WebService.ws_single_user + "?user_id=" + parameterValue);
HttpWebRequest UserDetailRequest = (HttpWebRequest)HttpWebRequest.Create(UserDetailUrl);
HttpWebResponse UserDetailResponse = (HttpWebResponse)await UserDetailRequest.GetResponseAsync();
StreamReader reader = new StreamReader(UserDetailResponse.GetResponseStream());
string UserDetailString = reader.ReadToEnd();
reader.Close();
XDocument XUserDetailDoc = XDocument.Load(new StringReader(UserDetailString));
if (((XElement)XUserDetailDoc.Element("main")).Element("result").Value == "success")
{
txtEmail.Text = ((XElement)XUserDetailDoc.Element("main")).Element("user").Element("email").Value;
txtFirstName.Text = ((XElement)XUserDetailDoc.Element("main")).Element("user").Element("fname").Value;
txtLastName.Text = ((XElement)XUserDetailDoc.Element("main")).Element("user").Element("lname").Value;
txtMobile.Text = ((XElement)XUserDetailDoc.Element("main")).Element("user").Element("mobile").Value;
}
}
Windows 8 Phone アプリ - C# と XAML を使用
GetResponseAsync は次のとおりです。
public static Task<HttpWebResponse> GetResponseAsync(this HttpWebRequest request)
{
var taskComplete = new TaskCompletionSource<HttpWebResponse>();
request.BeginGetResponse(asyncResponse =>
{
try
{
HttpWebRequest responseRequest = (HttpWebRequest)asyncResponse.AsyncState;
HttpWebResponse someResponse = (HttpWebResponse)responseRequest.EndGetResponse(asyncResponse);
taskComplete.TrySetResult(someResponse);
}
catch (WebException webExc)
{
HttpWebResponse failedResponse = (HttpWebResponse)webExc.Response;
taskComplete.TrySetResult(failedResponse);
}
}, request);
return taskComplete.Task;