Almost two weeks ago I posted about my first experiment with Amazon EC2, and how I was able to get an existing application (our Sproodle SaaS offering) up and running on EC2 in a couple of hours. That was the same day as Microsoft announced Windows Azure, and of course I wanted to try the same application to run on Azure as well. Two days later I finally got my Azure account, and to my delight I was able to get our application up and running on Azure in about 30 minutes. Which in my mind seriously rocked. In this post I will explain the steps I went through to deploy an existing application to Azure, and talk a bit about how Azure compares to EC2.
Oh, and I’m pretty sure this was the first real (real as in real application, not a Hello World sample) Windows Azure deployment from Finland (on the 29th of October) :).
Deploying an existing application to EC2
There are a bunch of Hello World-examples for how to create a small app and deploy it to Azure, but when I first did this deployment I couldn’t find a sample that showed how to take an existing application and deploy it. However, the mechanism behind deploying to Azure is pretty simple, and essentially what you need is a deployment project. In Visual Studio you can’t add just the deployment project to an existing solution, you always get a new web application as well. This may not seem that useful at first glance, but it’s actually not that hard to change it to deploy whatever project you want. Below you can find out how. I’m using a sample app for this article, since the project I actually used when I did this at PDC is a pretty large and complex beast.
Step 1. In your existing Silverlight application solution, add a new Cloud Service project
My sample application solution contains two projects. The first is the Silverlight application, which in this case just writes “I like clouds! on a blue background. The other project is a web application that shows the Silverlight app. No changes has been made to this project, it’s just straight out of the box.
Now, to add cloud goodness we have to cheat a bit. Currently (as far as I know) Visual Studio won’t let you add a Cloud Service project (which is needed for deploying to Azure) and have that deploy an existing web application. It always wants to create a new application for you. So what you can do is to add a new “Web Cloud Service” to your solution. Let’s call it “CloudService”.
Step 2. Get rid of the generated WebRole-project
When you add a new “Web Cloud Service”-project Visual Studio actually creates two projects for you. One is the deployment project (“CloudService” in this example), and the other is a web application (“CloudService_WebRole”). As far as I can tell the second one is just a regular web application.
The deployment project is set up to deploy the CloudService_WebRole-project, and I haven’t found a way to change which project it tries to deploy through the Visual Studio UI. So we need to wire it up to deploy our existing “SilverlightCloudApplication.Web” instead.
Step 3. Use notepad to edit the project file.
This is the scary part. If you’ve poked around in the Visual Studio project files before you know that they are just XML files, and note even very complex ones at that. It turned out that all we need to do in order to make “CloudService” deploy any web project we want is just change which project its deployment point refer to.
So what we first need to figure out is the ID for our “SilverlightCloudApplication.Web”-project. First close Visual Studio. Then open the file “SilverlightCloudApplication.Web.csproj” in notepad (or your favorite text editor). Look for an XML element called “ProjectGuid”, and copy the contents of that element. In my sample project here it was “{61CADBB5-24ED-4F11-848B-7754877F7A06}”, but it will be something different for you project.
Next open the project file for the “CloudService”-project. Look for an XML element called “ItemGroup”, and another called “ProjectReference” below that. You need to edit three things in there. First, change the “Include”-attribute of the “ProjectReference”-element to be the path to the project of the web application you want to deploy. Next, change the contents of the “Name”-element to be the name of your web application. And finally, change the contents of the “Project”-element to be the guid you copied from the web application project file earlier.
Below you can see a screenshot that gives you an idea of what the results of your edits should look like.
Save the file, and restart Visual Studio. When you open the solution you will see that the CloudService now refers to your web application (in this case “SilverlightCloudApplication.Web"). At this point you can safely delete the “CloudService_WebRole”-project, as it is no longer needed.
Now you should be able to build and publish your application to Azure. Happy cloud computing.
Comparing Azure to Amazon EC2
A lot of people have asked me which is better, Azure or Amazon EC2? First I want to point out that this is a bit of an apples to oranges-comparison. Sure, they both are part of that fuzzy bag of stuff called “cloud services”, but from a (service) perspective they are quite different. What Amazon does is give you virtual servers that you can use to run whatever you want on, and what Azure does is give you the ability to deploy web applications to the cloud. The difference is primarily that with Amazon you still have to operate and maintain the environment your application runs in, and with Azure Microsoft is taking care of all of that for you. And they seem to do it in a very impressive way. Their environment even takes care of staging for you, so that you can test your new deployment before you switch out the currently live one.
So which one do I prefer? I really like Windows Azure. I also like Amazon EC2. I think there’s room for them both. Currently I think Azure is the better choice if what you want to do is run a web application in the cloud. Most software developers do not want to have to operate the environment, for many reasons (cost being one of the most popular ones).
If you need full control over the environment your application runs in, you probably cant use Azure (at least not in its current state). For example, I have to admit that I ended up cheating a bit when I deployed Sproodle to Azure. Because it has a database and a bunch of WCF services on top of that database I couldn’t deploy those to Azure, since it doesn’t supply you with a SQL Server. I would have had to re-architect the services so that they can run in Azure on top of SQL Services (which is a completely different animal from SQL Server). My kung fu may be strong, but not strong enough to do that in half an hour. :) So what I did was keep the services in the EC2-environment I’d set up a couple of days earlier, and set up my Silverlight app to call them from there instead. So I ended up being double-clouded, the front end running on Azure and the back-end on EC2. Not ideal, but hey, it worked! :)
An interesting hack to a rather remarkable leap in deployment. My congratulations!
I foresee that this will become a lot more flexible very soon though. Give the Visual Studio guys a little while and soon you should be able to push-button deploy your application into the proverbial cloud.
As a friend of seamless integration, i very very much like this approach. The whole idea of having an application platform out there instead of an operating system waiting for you is just where we should be heading. Kind of like having a blogging engine, or Flickr, as a service and not just an account on a virtual Linux server where you will set up Wordpress or Gallery yourself, though of course on the next order or complexity. Admittedly, i do like both options; sometimes i like to tweak and sometimes i just want to deploy.
Now how on (virtual) Earth did you come up with the solution requiring the config xml file hacking? Pure hack-fu?
Posted by: llaurén | Thursday, November 13, 2008 at 10:22
Nicke, great to hear you got everything working so quickly!
I believe you should have been able to do this in Visual Studio without the XML hackery... just create a new _blank_ cloud service, add your existing web application to the solution, then right-click on the "Roles" node, choose "Add" and then "Web Role Project in solution." Choose your web app, and you should be done!
That should be all that's needed. Give it a try and send me email if it doesn't work for you! My email is [email protected].
Posted by: Steve Marx | Wednesday, November 19, 2008 at 08:01
Thanks for the article! After trying this, I discovered the ability to add a Silverlight app to a Cloud Web Role is actually already built into VS2008.
To add a Silverlight project to a Web Role project, simply right-click your project file in the solution explorer and select "Properties". In the Project properties view, the bottom-most tab on the left is "Silverlight Applications" - select this, and there is an "Add..." button that allows you to add (and configure) a new or existing Silverlight app to your web role. Simple as that. (I assume this tab is standard - if not, the only extras I've installed are the Silverlight SDK and Silverlight Tools for VS SDK)
Posted by: mrrob1978 | Monday, December 01, 2008 at 22:52
Hi Nicke
I need your help in deploying a web service on azure hosted service. according to my knowledge only web app can be deployed. but i want to deploy my web service on azure platform. Is it possible?
Posted by: Account Deleted | Monday, May 25, 2009 at 17:11
Hi:
I followed your instructions and everything worked as expected in Visual Studio. I was able to start the service up without any issues.
However, when I am trying to deploy the app into Azure it fails. The status of the deployment constantly goes from "Initializing..." to "Stopping...".
Any ideas?
Thanks,
Tolga
Posted by: Tolga | Wednesday, August 25, 2010 at 21:51