Building Windows Phone Applications Using Windows Azure

Phone + CloudWindows Phones provide many opportunities for developers to build great applications. Nevertheless, in some cases a developer is limited by the attributes specific to any mobile device – constrained processing, battery life, limited storage, and intermittent connectivity.  Consequently, it’s important to tie into services off of the device, ideally in a location with scalable processing, plenty of power, elastic storage, and ubiquitous connectivity. Enter cloud computing with Windows Azure.

In many ways, cloud computing levels the playing field. Any developer can tap into a larger – and virtually limitless – pool of resources from which to pull.  For developers, Windows Azure – Microsoft’s cloud-computing platform – is a great compliment to mobile application development. Simply put, Windows Azure allows you to focus on your application. You don’t have to worry about managing or monitoring the operating system, just as you don’t have to worry about the hardware our network. As a managed service, Windows Azure takes care of things items for you.

To make it easier for Windows Phone developers to use Windows Azure, we have created the Windows Azure Toolkit for Windows Phone. This toolkit provides a set of Visual Studio project templates that give you an advanced starting point for building Windows Phone applications tied into services running in Windows Azure.  The toolkit also includes libraries, sample applications, and documentation.

Today we’ve released version 1.3 which includes some great updates, including:

For more information on this release you can watch this video on Channel 9:

To get started, visit the Windows Azure Toolkit for Windows Phone on CodePlex. While you can review the source code online, I recommend you download the self-extracting executable. This tool not only gives you all the source code, but also a Visual Studio extension that includes the project templates and a dependency checker that ensures you have all the required prerequisites.

Configuration Wizard

Once installed, you’ll get two new project templates under Cloud templates – Window Phone Cloud Application and Windows Phone Empty Cloud Application.

Windows Phone Cloud Application

Create a new Windows Phone Cloud Application. This will launch a wizard that will collect information from you required for running your application with services. The wizard is adaptive, and will only request information based on what you select.

New Windows Phone Cloud Application Project

Choose both Windows Azure Storage and SQL Azure Database – this way you can try everything you. Just as Windows Phone provides an emulator for development, so too does Windows Azure provide an emulator to simulate running applications in the cloud. Consequently, in the next step, choose the Use Storage Emulator – you can always change this setting later. Similarly, for SQL Azure, choose Use local SQL Server instance.

One of the gems in this toolkit is the built-in support for the Microsoft Push Notification Service (MPNS) – without having to write a single line of code you can host your MPNS services in Windows Azure that are already connected to your application.

Microsoft Push Notification Service

In the last step, you can choose how to manage user authentication. The toolkit provides two forms of user management – a simple ASP.NET membership store (which provides typical username/password support) or the Access Control Service (ACS). ACS is a Windows Azure service that allows you to tap into existing identity providers such as Live ID, Google, Yahoo, and Facebook – in fact, even corporate identities are supported through ADFS. The toolkit makes using ACS extremely easy – not only will it collect information needed to use ACS, but it will also reach out to the ACS management rest endpoints to set everything up automatically. For a detailed explanation, see Windows Azure Toolkit for Windows Phone 7 1.2 Will Integrate With ACS from Vittorio Bertocci.

User Authentication

Once the wizard has run its course you’ll have a solution ready to run – so hit F5!

Login

You are first presented with the opportunity to login. Depending on the user authentication mode you choose, you’ll either use ACS or create a new user.

NOTE: In order to consume the REST services over HTTPS in a phone device or in the Windows Phone Emulator, you need to use a trusted SSL certificate. If you do not have one, you can use a self-signed certificate, but you need to install it in the phone before consuming the services. Since the Computer Emulator always uses the 127.0.0.1 self-signed certificate, we need to install it in the Windows Phone Emulator before continuing with the next steps.

Once you’ve logged in you can start to try out the various aspects of the toolkit. There are five areas to explore:

  • Push Notifications
  • Windows Azure tables
  • Windows Azure blobs
  • Windows Azure queues
  • SQL Azure

To make it really simple to try out and test the push notifications – as well as provide you a demonstration of how to go about registering a notification channel, storing it in Windows Azure tables, and then sending a message to the phone – we have also included a simple web application that you can use to send notifications to the phone. First, enable push notifications on the client …

Enabled MPNS

… then log into the web application running in the Windows Azure compute emulator (admin login is listed in the documentation) and choose the Microsoft Push Notifications tab. You should see a channel established for your user. Type a message then click Send Raw.

Send a notification

Back on the emulator you will see that the application has received the message from the MPNS. Try it out for toast and tile notifications too!

Receiving a raw messageReceiving a toast and tile message

Not bad for an out-of-the-box experience! You can also test out toast and tile notifications.

While this is a sample application, the value is that it includes all the required piping to handle the Windows Phone push requests from the client, surfacing them through the web application, and then letting the admin send notifications back to the phone.

And of course, there’s more – explore the ability to create and delete tables, enter rows of data, upload pictures from the device camera into blob storage, enqueue and dequeue messages in queues, and display read-only data in SQL Azure.

BabelCam

One of the more recent updates to the toolkit includes the sample application BabelCam. BabelCam started as a proof-of-concept application I built for my MIX11 talked Building Windows Phone 7 Applications with the Windows Azure Platform. Since then we’ve not only cleaned up and included the source code, but we’ve also published to the Windows Phone marketplace – download BabelCam and try it out!

We’ve been able to move very quickly in developing this toolkit, based largely on great feedback we’ve received from users – please keep it coming! As a refresher, here are some of the updates we’ve made over the last six months:

Mango opens up a lot of new opportunities for us to build new capabilities and applications that combine the best of Windows Azure and Windows Phone – exciting times ahead!

Be sure to download the Windows Azure Toolkit for Windows Phone today.