Architecture & DesignCreating a Simple Windows Azure Application

Creating a Simple Windows Azure Application

Developer.com content and product recommendations are editorially independent. We may make money when you click on links to our partners. Learn More.

In earlier articles, I presented an introduction to the Microsoft Windows Azure platform. Now I’ll show you how to develop applications targeting the Azure platform. You’ll start off with a very simple cloud application.

Getting the Cloud Computing Tools Ready

To develop applications on the Azure platform, you will need to get the necessary toolset downloaded and installed. This includes Visual Studio 2010 and the Azure tool kit.

Hands-On Azure Development

Fire up Visual Studio 2010. Click to create a new project and select the Cloud node from under Visual C# templates as shown in Figure 1.

Selecting an Azure Cloud Project Template
Figure 1: Selecting a Cloud Project Template

Click OK to proceed. As soon as you click OK, you are prompted to select the type of roles for the Azure application as shown in Figure 2.

Selecting Roles
Figure 2: Selecting Roles

Select The ASP.NET Web Role. When you hover your mouse over the selected role, you are prompted to determine if you would like to delete it or rename it. Click the pencil icon to rename the role as shown in Figure 3.

Renaming the Web Role
Figure 3: Renaming the Web Role

In this case, rename it to “MyASPNETWebRole”. Click OK for the project to be created.

Once you do this, Visual Studio 2010 does its code-behind and generates the item shown in Figure 4 within Solution Explorer.

The Role Added to Solution Explorer
Figure 4: The Role added to Solution Explorer

You will also notice that a default.aspx web page has been created with the following contents

<%@ Page Title="Home Page" Language="C#" MasterPageFile="~/Site.master" AutoEventWireup="true"
CodeBehind="Default.aspx.cs" Inherits="MyASPNETWebRole._Default" %>

<asp:Content ID="HeaderContent" runat="server" ContentPlaceHolderID="HeadContent">
</asp:Content>
<asp:Content ID="BodyContent" runat="server" ContentPlaceHolderID="MainContent">
<h2>
Welcome to ASP.NET!
</h2>
<p>
To learn more about ASP.NET visit <a href="http://www.asp.net" title="ASP.NET Website">www.asp.net</a>.
</p>
<p>
You can also find <a href="http://go.microsoft.com/fwlink/?LinkID=152368&clcid=0x409"
title="MSDN ASP.NET Docs">documentation on ASP.NET at MSDN</a>.
</p>
</asp:Content>

You will notice that the “MyFirstAzureProject” in the Solution Explorer has the “MyASPNETWebRole” as one of its offered roles.

Besides the web role, the wizard also creates a couple of additional files

FileName Purpose
ServiceConfiguration.cscfg      This is a service configuration file and contains settings for all roles offered by the Azure service. In our case, it contains settings for the MyASPNETWebRole.
ServiceDefinition.csdef     This is the service definition file. You can read more about it at http://msdn.microsoft.com/en-us/library/ee758711.aspx

Now, add some custom code to your first Azure application. See the highlighted section of the next code listing to see what you need to change in default.aspx.

<%@ Page Title="Home Page" Language="C#" MasterPageFile="~/Site.master" AutoEventWireup="true"
CodeBehind="Default.aspx.cs" Inherits="MyASPNETWebRole._Default" %>

<asp:Content ID="HeaderContent" runat="server" ContentPlaceHolderID="HeadContent">
</asp:Content>
<asp:Content ID="BodyContent" runat="server" ContentPlaceHolderID="MainContent">
<h2>
Welcome to cloud computing.
</h2>
<p>
To learn more about ASP.NET visit <a href="http://www.asp.net" title="ASP.NET Website">www.asp.net</a>.
</p>
<p>
You can also find <a href="http://go.microsoft.com/fwlink/?LinkID=152368&clcid=0x409"
title="MSDN ASP.NET Docs">documentation on ASP.NET at MSDN</a>.
</p>
</asp:Content>

You can toggle to the design view of default.aspx to see if you like the layout and make any change you deem fit. Figure 5 shows how the page looks currently.

The Start of your Azure Cloud Application
Figure 5: The start of your Cloud Computing application

You are now ready to run the cloud application. One thing to note is that the Azure emulator needs to be run elevated. Hence you will have to restart Visual Studio as elevated in case you did not do so in the first place.

Once you Ctrl+F5, Visual Studio readies the project to deploy to the emulator as shown in Figure 6.

Deploying the Visual Studio 2010 Azure Cloud Emulator
Figure 6: Deploying the cloud emulator

Once it is done, you can see the following screen (Figure 7):

The Loaded Visual Studio 2010 Azure Cloud Emulator
Figure 7: The loaded Cloud emulator

Click OK to dismiss the dialog and launch the emulator. The emulator sits in your system tray (the blue windows icon as shown in figure 8.)

The Azure Cloud Emulor in the Windows System Tray
Figure 8: The Cloud emulator in the System Tray.

Once the emulator launches, it will go ahead and launch the default.aspx page.

Running Your Application in the Cloud Emulator
Figure 9: Your Cloud Application running in the emulator

There, you now have your first cloud application running in the emulator. You can them proceed to deploy the application to the cloud. You’ll learn how to do that deployment in the next article!

Summary

In this article, you saw how to create an Azure application. Hopefully you will find this illustrated example useful to get you excited about the cloud computing platform.

About the author

Vipul Patel is a Software Engineer currently working at Microsoft Corporation. He is currently working in the Office Communications Group and has worked in the .NET team earlier in the Base Class libraries and the Debugging and Profiling team. He can be reached at vipul_d_patel@hotmail.com

Get the Free Newsletter!

Subscribe to Developer Insider for top news, trends & analysis

Latest Posts

Related Stories