This week I am taking some time to discuss integrating your WP7 app with Windows Azure and the Microsoft “cloud”. This can be hugely beneficial if you happen to write the next “farmville”. The cloud offers the possibility to scale up and out, and in a matter of minutes.
In this post, I will show a quick demo and the tools you’ll need for constructing your all-embracing nimbus. Let’s get the basics first. You’ll need IIS 7, the WP7 developer tools, and the Windows Azure SDK. Once you get those out of the way, head over to the MSDN All-In-One Code team blog and download the demo. Ahhh, now for the fun stuff.
But first a bit of background. A core component to the Windows Azure platform has been neatly constructed in something we like to call “roles”, or runtimes for execution. Roles can be quickly targeted to any platform “in the cloud” and allow you to specify however many instances of your service or web application you would like. Roles are also easily configured in your role configuration file, or within the Azure platform app fabric portal. Web applications (defined within a web role) can be pushed across several endpoints with the push of a button! Wow, right? Running as many background processes (worker roles) as you need is also supported. I know…I was excited too.
This demo showcases the Windows Azure Datamarket, another service being provided by Microsoft’s cloud which allows you to consume cloud data using a REST service and the OData protocol. Read the whitepaperfor more fascinating tidbits. The Azure DataMarket requires your Microsoft Live Id and a data service subscription. Luckily, this demo uses a free Web Crime service provided by Data.gov. There are several others in the store which provide real time data feeds.
Enough chit chat, let’s see this in action. First you’ll want to pull down your Account subscription key and add it to the CrimeService.svc.cs file, i.e.:
private static string azureDataMarketAccountKey = “ey1Oab3KdvlEkIhk=”; public List<CityCrimeWeight> GetCrimes() { List<CityCrimeWeight> results = new List<CityCrimeWeight>(); datagovCrimesContainer svc = new datagovCrimesContainer(new Uri(“https://api.datamarket.azure.com/Data.ashx/data.gov/Crimes/”)); svc.Credentials = new NetworkCredential(“yourLiveId”, azureDataMarketAccountKey); // Obtain all crime data in New York. var query = from c in svc.CityCrime where c.State == “New York” select c; …
Next, fire up the demo in VS 2010 along with the Windows Azure Compute Emulator. This will enable you to watch web roles boot up. Here you can see I have specified two instances in my service configuration (csfg) file. The UI emulator will show your service endpoints along with your role runtime statements.
Once you have this piece in play, you’re almost ready to go. You can fire up your WP7 client application (preferably in another instance of Visual Studio) and see your cloud services at work. You may want to change the ServiceAddress property in the MainPage code behind depending on where the CrimeService web role was deployed, i.e.:
private static string ServiceAddress = “http://127.0.0.1:81/CrimeService.svc/Crimes”;
This demo shows how easy it is to expand your WP7 application into a Azure Datamarket Cloud Consuming Machine! Hope you enjoyed.