O'Reilly logo

Beginning Windows® Phone 7 Application Development: Building Windows® Phone Applications Using Silverlight® and XNA® by Robert Fonseca-Ensor, Karli Watson, Nick Lecrenski

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

CHAPTER 9 EXERCISE SOLUTIONS

Exercise 1 Solution

The valid HTTP methods (verbs) in the list are GET, DELETE, POST, and PUT (a, c, d, and e). ZAP isn't allowed, and EXSANGUINATE is just plain silly.

Exercise 2 Solution

You use the UploadStringAsync() method of the WebClient class and respond to the UploadStringCompleted event.

Exercise 3 Solution

The following call will fail:

ResultTextBox.Text = sr.ReadToEnd();

If you access the user interface, you must use Dispatcher, as in this example:

string text = sr.ReadToEnd();
Dispatcher.BeginInvoke(new Action(() => ResultTextBox.Text = text));

Exercise 4 Solution

Recall that the Flickr API error message format is as follows:

<?xml version=“1.0” encoding=“utf-8” ?>
<rsp stat=“fail”>
  <err code=“[error-code]” msg=“[error-message]” />
</rsp>

One way to achieve the desired result and extract this information in case of error is to modify the GetUserRequestCallback() method as follows:

private void GetUserRequestCallback(IAsyncResult result) { HttpWebResponse response = (result.AsyncState as HttpWebRequest) .EndGetResponse(result) as HttpWebResponse; XDocument resultXml = XDocument.Load(response.GetResponseStream()); string status = resultXml.Root.Attribute(“stat”).Value; if (status == “ok”) { string userNsid = (from user in resultXml.Descendants(“user”) select user.Attribute(“nsid”).Value) .FirstOrDefault(); HttpWebRequest getPhotosRequest = WebRequest.CreateHttp( flickrUriHelper.GetUri( “flickr.people.getPublicPhotos”, new Dictionary<string, ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required