I recently got a beta invite for the Windows Azure hosting and storage services and immediately set about writing a simple hello world hosted app. I wanted to test both the Web role and the Worker role so I was looking for a simple scenario for that. I liked the new Windows Live feature of displaying a new background image on http://live.com site. They started doing this for the recently concluded Olympics but have since continued to display different images from around the world. I had written a simple windows service that checks the page every day to download any new images. I decided to port this app over to Windows Azure. I could use the Worker role to host my live image “poller” and store any new images in Windows Azure Blob storage. Then I can write a simple web app that will display all images stored in my blog storage.
Downloaded and installed Windows Azure SDK and Windows Azure tools for Visual studio.
Even if you don't have a Windows Azure invite, you can download the SDK and try it out by developing against the development fabric. The SDK contains all needed runtime components to host a local development fabric and storage services.
Launch VS 2008 and started a new Cloud Service project. From the predefined templates, I chose the Web and Worker Cloud Service template. This gave me a cloud service project with 2 roles in it (Web and Worker roles).
The worker role is intended for background processing jobs. Worker roles cannot accept incoming requests but can make unlimited outgoing requests. The roles are run in a sandbox domain which means it doesn’t have any access to local file systems. All storage requirements are to be solved by using one of the three Windows Azure storage services (Blob, Queue and Table). For this sample all I needed to do was store the images in the blob service and add some metadata such that blobs can be rendered by a browser.
Before downloading all images, I needed to create a unique container where I would be storing these image blobs. The Windows Azure SDK ships a very useful REST based API to programmatically access the storage service. Here is the code to do that.
BlobStorage and BlobContainer types are part of the REST storage access API and RoleManager is Windows Azure logging utility. I set the container visibility to public for ease of access. (Don't bother trying to delete content as only GET requests are anonymous, all other operations require my unique access key)
Primary job of the poller would be to download http://live.com resource and look for the background image. It will then inspect the blob storage to see if the image already exists and if not add it to the container. We also set the blob’s content type to image/jpeg so browsers can render the blob link as an image.
Done. Its that simple. Now details about blobs in the live search container can be accessed via a simple get request to http://maheshwar.blob.core.windows.net/livesearchimages/?comp=list .Here is the list as of writing this post.
I just wanted to have a simple ASPX page that just lists all images and their download timestamp. I once again used the REST API’s to download all blobs from my livesearchimages container and data bound the columns to a simple DataGrid.
Here is the code to retrieve all Blobs. To make data binding easier, I just wrapped the contents of my blob in to a LiveImageMetadata class.
And finally the DataGrid definition.
After testing locally, I updated all references to my cloud services url and published the service.
You can view all images downloaded by visiting link http://maheshwar.cloudapp.net/LiveSearchImages.aspx
That looks simple but it was not so straight forward experience moving it from my development fabric to the cloud fabric. I have some feedback to the Windows Azure team on how to make the developer experience simpler.
Having said that I see the huge potential Windows Azure has. Since the hosting services has .NET 3.5 installed it means you can host any (WCF/Silverlight/ASPX/ASMX) services on the cloud. I am going to move my Silverlight projects from http://maheshwar.net/bog/projects over to Azure.