Supporting Billions of entities/rows for Mobile – Mobile to Cloud Series - Part 10 – Writing a Windows Phone 7 Client to consume RESTful data from Azure (Microsoft Cloud)
This is the last post in a long series. This is a post about connecting Windows Phone 7 applications to a RESTful service hosted in the Microsoft cloud, aka Windows Azure. Before moving on into this particular post, I’m making a few assumptions about what you’ve already done. First, I expect that you have already created a RESTful service, which was explained in detail in previous posts. Complete source code was provided as well as guidance about building the service itself. Second, I will assume that you follow the guidance about what operating systems and developer tooling you are running. |
Supported Operating Systems |
Before you commit writing Windows Phone 7 applications you need the right operating system. I am a super big fan of Windows 7. I've had the same instance loaded (in and out of sleep mode) for weeks. It is incredible how stable and efficient Windows 7 is. I am not saying this because I work for Microsoft. I've been using MS operating systems since DOS 3.0. Windows 7 rocks. 'Nuf said. Supported Operating Systems
|
Windows Phone SDK |
The Windows Phone SDK includes a number of powerful tools, in addition to Visual Studio. Let's talk about what is included.
|
Download Link for the Windows Phone SDK |
This is the download link for the Windows Phone 7 SDK. Everything I talked about earlier in this post, is included. It is your one-stop-shopping link. ![]() |
You will need the Azure SDK |
![]() |
Starting Visual Studio and Creating Your Project |
Silverlight for Windows Phone 7 |
Select "Silverlight for Windows Phone 7" in the left template pane. Next select "Windows Phone Application" in the middle pane. Finally, specify a "Name" and "Location" for your project. ![]() |
Version 7.1 – Mango – Windows Phone 7 |
For the Phone OS version, choose 7.1. You could select an earlier version, but I will select 7.1 here. This version represents the "Mango" release, the release with over 500 new features. ![]() |
The files we will modify – Only 2 |
This is what the generated solution looks like. We will only need to modify two files. We will modify these 2 files: ![]()
|
Modifying MainPage.xaml |
The red box represents the page title. The next screen will demonstrate how we can modify the page title by changing the XAML markup. ![]() |
Changing the Page Title |
Implementing the ListBox |
Modifying Code Behind – MainPage.xaml.cs |
Adding code to MainPage Constructor |
To keep things simple I decided to load the list box in the MainPage constructor. Notice I typed in the method, "LoadListBox." But I haven't implemented "LoadListBox()" yet. That is the next step. ![]() |
Generating LoadListBox() |
Erasing Code Not Needed |
Here is what the empty method looks like. I will erase "throw new NotImplementedException()" with the real code that I want to execute. ![]() |
Pointing to the RESTful Service – the URI |
Notice that I added a property called "_baseServiceAddress." You will need to go to the Windows Azure Portal to get the address of your hosted service. This was covered in detail in previous posts. See Step 3 - DNS name below. Also note I've added some code that builds the URI that will access our RESTful service. See "LoadListBox()." |
Adding References |
Adding a reference gives our Windows Phone 7 application access to additional functionality not provided with the default Windows Phone 7 project. In this case we will add "System.Servicem odel.Web." This assembly will let us parse the JSON code that comes back from the Azure-hosted RESTful service. ![]() |
Adding using statements to Code Behind |
Loading our Clipboard – Using WP7.exe |
Start the previously mentioned "WP7.exe" application. To populate your clipboard with the previously mentioned "using" statements, click on "WP7 References." Return back to Visual Studio. ![]() |
Pasting code from the Clipboard – adding the “using” statements |
Right-mouse click just below the last "using" statement and select "Paste." ![]() |
Implementing all the code in LoadListBox() |
Loading our Clipboard – Using WP7.exe |
Start the previously mentioned "WP7.exe" application. To populate your clipboard with the code for "LoadListBox()", click on "LoadListBox()." Return back to Visual Studio. ![]() |
Pasting code from the Clipboard – adding code to LoadListBox() |
Highlight the entire method "LoadListBox()," right-mouse click, and select "Paste." Congratulations. We are done. You are ready to compile and run the application. Explained earlier in the post. Be sure that you put wp7.exe and wp7.xml in the same folder.
![]() |
Compile our Application |
To compile your application, go to the menu and select "Build / Rebuild Solution." The output window should indicate "O failed." ![]() |
Run our application |
You are ready to run the application in the emulator. Go to the menu system and select "Debug / Start Debugging." ![]() |
MainPage.xaml |
|
MainPage.xaml.cs |
|