When Written: Mar 2011
So you are interested in Cloud Computing? Perhaps your boss has suggested that the company needs to investigate this as it seems to be the hot topic at the moment or perhaps you can see a real benefit in moving your current web application off those servers of yours that will be needing replacing before long? Or you have an idea for a new web based application that needs to scale and have high availability throughout the globe? How tricky is it to move an application from a traditional hosting environment to a Cloud one? Lets first consider a simple .NET web application and moving it to Microsoft’s Azure environment. Often when first investigating a new technology and its implementation one is confronted with editing files in notepad and then having to compile the resultant code via a cryptic command line process, not the sort of thing to endear the process to you. However whilst Cloud Computing is relatively new, the development tools that Microsoft have for it are remarkably comprehensive. As one would expect there is an SDK (Software Development Kit ) available and this integrates with Microsoft’s code development product, Visual Studio 2010. This integration process now uses the Microsoft platform installer so that all the downloads and the configuration of the various components is automatically done for you with a single click. What gets installed is more than the necessary code modules for syntax checking and the documentation but also several other applications that will enable a complete Azure environment to be generated locally on your machine so you can fully debug and test your application locally before you go live and move it out onto the Cloud and start to incur costs. As Azure is 64bit it is best that your Visual Studio and Azure SDK is installed on a 64bit version of Windows7 although it will work on 32bit Windows there are warnings of some possible compatibility errors, it says that ‘the use of native code execution or .Net Full Trust features such as P/Invoke may require migration to 64-bit’ so just be aware of this issue.
Development Tools
So you have installed your SDK, now what? Open Visual Studio and select ‘create new project’ and choose your preferred programming language of either VB or C# and choose the ‘Cloud’ category. After picking Windows Azure Cloud Project there are several types of projects available here, I would suggest selecting first one ‘ASP.NET Web Role’ or if you prefer using the MVC programming model then choose the second option. Once selected after much whirring of the local hard disc, your first project code will eventually appear, looking very like a basic ASP.NET web project, but with some extra configuration files. As with other projects, Microsoft provide a couple of demo pages so that there is something that can run from the initial creation. All you need to do is click the run icon and you should see the usual compile messages that you would expect with a standard ASP.NET application but then a lot of extra stuff goes on as the local Azure environment is setup and the services are started, but watch out here. For the Azure environment to run Visual Studio needs to run with elevated permissions and so you wil need to close it and restart it with ‘Run as Administrator’. When you click the run application icon in Visual Studio for the first time it will take some time for all the Azure background services to start up, but thankfully this does not happen on future debug runs of your application. Eventually a browser window will open with your web application pages in it, nothing very exciting but at least it is working. We will cover coding for the Cloud and some of the issues in a future article, but for now we at least have something we can try to deploy.
Deploying to the Cloud
The next stage is packaging this app and deploying into the Cloud. To do this you need to register for an Azure account by first going to http://www.microsoft.com/windowsazure there is a free trial until June 20th and if you have a MSDN subscription or a Microsoft Partner you may also qualify for a free trial, the various packages and trials allow for different levels of resources to be used so read them carefully before you decide. When signing up for a free trial you will still be asked to supply either a credit card or a Microsoft Purchase order number as both these methods of billing can be used should your application exceed the amount of resources that your subscription plan allows. In the event of this happening you should receive emails when you reach 75%, 100% and 125% use of your subscription plan so you should have time to decide what to do about the extra traffic your web application is getting before the costs ramp up unexpectedly. Once you have signed up using your Windows Live ID you will get a confirmation email and a link to log into the ‘Microsoft Online Services Customer Portal’ You then need to select the subscriptions tab and check that the service is active, this may take a little while so allow 24 hours. Once you have an active subscription you have to set up a hosted service within Azure. To do this go to https://windows.azure.com and click on ‘New Hosted Service’ and follow the prompts, you will also need to set up a storage account which you do in a similar fashion. Once this is done you can return to your Visual Studio project and in the project explorer panel you will see two main groups of code files, select the group with the ServiceConfiguration.cscfg file in as this is the Cloud specific area of your project. Now select ‘build | Publish’ you will then be presented with a screen asking for the account name and the host account and storage accounts. If all is set up correctly, and as long as you follow the prompts carefully, it should be then after a few minutes you should have a working web application hosted on the Azure Cloud. If you update this app with a newer version your previous version will be deleted and will be unavailable to users whilst the update is going on. This we found a little disappointing as continuity of service is one of the great mantras of the Cloud, we shall be investigating to see if there is a way around this behaviour.
The final test is to point your browser at the url of your Cloud application, in our case it is http://cloudpro.cloudapp.net . It is a lot of hoops to jump through to get up and running such a simple web page in this case but thankfully a lot of these tasks only need to be done once and with the computing power of the Cloud now available to you the sky is the limit!
Article by: Mark Newton
Published in: Mark Newton