Creating a Windows Azure Application: A Step-by-Step Guide
Windows Azure, as powerful and intriguing as it is, can seem daunting to many developers seeking to take their first steps into cloud computing. Developers may have the perception that Windows Azure is too big to wrap their arms around. The perception that Windows Azure is too big and too different is a fallacy.
Need Help? If help with Windows Azure is needed, the Microsoft Platform Ready team is available at http://www.microsoftplatformready.com. The site contains many helpful resources such as a jumping off point for tools, insightful blogs, email, chat, and phone help options, and much more. This is also were Microsoft Partner Network members can find information for earning a “Powered by Windows Azure” logo. If promotional help is needed, the Microsoft Platform Ready team can help with that as well via the Windows Azure Marketplace. In this article, developers new to Windows Azure will learn how to create a basic ASP.NET MVC3 application, which uses SQL Azure as the database. By the end of this article, you will realize that the Windows Azure platform isn’t more complicated than the traditional Microsoft .NET development landscape – just a bit different.
In order to start with a solid foundation, it is important to understand a few of the core Windows Azure concepts. Both Windows Azure and SQL Azure are hosted in Microsoft’s world-class data centers around the world. Windows Azure provides developers with on-demand compute, storage, networking, identity management, caching and content delivery capabilities. SQL Azure provides relational database capabilities as an on-demand service. Windows Azure is an extremely rich platform, and there is a lot you can do with it.
In order to demonstrate building an application on Windows Azure, we’ll create a basic ASP.NET MVC3 site that uses SQL Azure as the database. The ASP.NET MVC3 site will be hosted in a Windows Azure web role (a container for your web application). The application you will build is a web site that can be used to track your personal golf history. The web site will store a record of each golf course played, the date it was played, score, and a few other key golf statistics. By the time you’re done, you’ll have a fully functional web application running in Windows Azure. Let’s get started!
To begin, you’ll want to make sure you have a few prerequisites installed on your development machine. We’ll add a few more components along the way, but to get going you’ll need at least the following:
- Windows 7
- Visual Studio 2010
- Microsoft Web Platform Installer 3.0 (this will be used for installing the additional tools)
- Windows Azure SDK for .NET
- ASP.NET MVC3 runtime & tooling
Once Visual Studio 2010 is installed, the easiest way to get started is to go to Windows Azure .NET Developer Center at https://www.windowsazure.com/en-us/develop/net/. Clicking on the large green “install” button will start the process of installing the necessary tools.
From there you will be prompted to the launch the Microsoft Web Platform Installer, which will load the necessary Windows Azure developer tools onto your machine. Part of the tooling to be installed will be the Windows Azure development and storage emulator. These emulators allow for a majority of Windows Azure development to be done locally on a development machine, without any need for connecting to a Windows Azure data center.
If you need any help getting started, you can always ask for help via the Microsoft Platform Ready site at http://www.microsoftplatformready.com.
With the necessary tools installed, it’s time to start creating the site.
Step 1 - Create an ASP.NET MVC3 Site
To begin, launch Visual Studio 2010 as an Administrator. You will need Administrative permissions once we start testing the application with the Windows Azure development emulator. Create a new ASP.NET MVC3 web application and name it “MyGolfStory”.
You're going to create a new Internet Application. For the purposes of this demo you will not need to create a unit test project, but a best practice would be to do so.
Creating a new ASP.NET MVC3 project adds several usefull references for us. One of those is a reference to EntityFramework. You will be using Entity Framework 4.1 as the ORM (Object Relational Mapper) for our data access layer. Entity Framework can be used with SQL Azure just like it would with SQL Server on-premises. To learn more about Entity Framework, please visit http://msdn.microsoft.com/en-us/data/aa937723.
Next, make some minor user interface adjustments for the My Golf Story site. Modify the standard ASP.NET MVC3 layout to have a different background color (green), remove the login control, and add a few tabs that will later be used to manage golf courses and rounds.
The site’s background color is defined in the Content\Site.css style sheet. Change the background color to green.
Since the site isn’t going to have any user management features, the default login view and also the associated configuration from the web.config file can be removed. Open the \Views\Shared\_Layout.cshtml file and remove the ‘logingdisplay’ <div>. In order to get the default layout to look good, you can add an empty <div>.
The _Layout.cshtml file also contains a list that serves as the navigation menu for the site. The site will need two more menu options – "Courses" and "Rounds". These will map to the Courses and Rounds controllers and views to be created later.
When finished, the code should look like that in the image below.
Next, open the Web.config file and remove the default ‘ApplicationServices’ connection string and elements related to membership. While they’re technically OK to leave, they’re not being used and removing them prevents any chance of errors related to code that may try to access them and the database not being available.
With the basic layout of the site complete, work can now continue with creating the data model.