Practicing Microsoft Azure: Part 7 (Azure Web Role Project)

Before reading this article, I highly recommend reading the following previous parts:

Creating Azure Web Role Project

This article offers a real taste of creating a complete Windows Azure service life-cycle by putting “Platform as a Service” into practice. At the end this, you will fully understand the complete flow for building a simple ASP.NET Web Role project (First “Hello World” program in Azure) under Windows Azure and the mechanism of deploying that simple application into the cloud climate.

Prerequisites

This article assumes you have at least a minimal understanding of .NET development, especially ASP.NET with C# and Object-Oriented Programming concepts. You will need the following hardware and software to complete the practice exercises in this article:

  • One of the Windows 7 editions, Windows Server 2008 with Service Pack 2, or Windows 8

  • Visual Studio 2010, or any latest edition

  • Windows Azure SDK

  • A computer capable of running the latest Visual Studio.

  • Running Internet Information Service

  • An Internet connection to work with Windows Azure

Getting Started

Now, let's get started with developing Windows Azure services. The objectives of this section is to get you started with a hands-on experience in building your own cloud services. In this example, you will develop, build and deploy a simple Windows Azure web role service to the cloud. Initially, we will build the complete service in the development fabric and then deploy it to the cloud.

Windows Azure services

Creating Web Role Project

The Web Role designed for making Web Sites or services accessible over HTTP typically contains multiple services and websites. It offers all the features of the Worker role, as well as supports IIS. To start with a cloud Azure service project, it is necessary to first configure all the relevant Azure SDK tools along with IIS. To debug and test your first Azure application in the compute emulator, first you need to start the Visual Studio IDE with administrative privileges. Then, go to New Project and select Cloud from the C# language bar and start an Azure cloud service project as in the following:

azure cloud service

Even as the new project is being selected from a template, the following (an ASP.NET Web Role) appears on the right in the Windows Azure Solution panel, meaning that your solution will contain one Web Role built with ASP.NET itself. Hence, choose a web role and assign a meaningful name and proceed as in the following:

template

Then, Visual Studio creates a couple of essential files automatically that will be shown in the Solution Explorer. The project is identical to a standard ASP.NET web application, since you are creating an ASP.NET project and are binding it to a web role later. The Roles folder locates the significant configuration file, both for local and cloud deployment in the form of a .cscfg. The project is hosted inside a normal Visual Studio solution that also contains a cloud project as shown in the Solution Explorer.

Solution Explorer

Since this project is a simple hands-on exercise with the Azure service, open the Default.aspx the from hWorld web role and place the following simple construct containing a server-side label control and simple “Hello world” message in the heading as in the following:

  1. <%@ Page Title="Home Page" Language="C#" MasterPageFile="~/Site.Master" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="hWorld._Default" %>  
  2.   
  3.    <asp:Content ID="HeaderContent" runat="server"  
  4.       ContentPlaceHolderID="HeadContent">  
  5.    </asp:Content>  
  6.   
  7.    <asp:Content ID="BodyContent" runat="server" ContentPlaceHolderID="MainContent">  
  8.        <h1> Hello World, Windows Azure Service</h1> <br />   
  9.        <asp:Label ID=" lblTime" runat="server" />  
  10.    </asp:Content> 

In the code-behind file, assign the current time to the Label within the Page Load event that will display the current time of the zone where the server is located as shown in the Listing.

  1. namespace hWorld  
  2. {  
  3.    public partial class _Default : Page  
  4.    {  
  5.       protected void Page_Load(object sender, EventArgs e)  
  6.       {  
  7.          lblTime.Text = DateTime.Now.ToString();  
  8.       }  
  9.    }  

Testing in Local Emulator

After we are done with the necessary form control placement and corresponding server-side coding, save the entire solution and debug it via F5 to test it in your local environment before deploying it into the cloud. As in the following, it is running as shown by the message as well as the server's current time.

Testing in Local Emulator

Go to the Notification Area of the Windows Taskbar and click the Windows Azure icon. When you click the icon, you receive a comforting message saying that everything is fine with the compute emulator and storage emulator.

comforting message

If you right-click the icon and choose Show Compute Emulator UI, you end up with the Local Emulator Interface. The tree in the left pane of the compute emulator window offers details about the local deployment of the “Hello World” project. In the user interface, you can see that the project contains a role named hWorld that has just one instance named 0. If you select this instance, the right pane of the window shows numerous trace messages. This pane reports all the events that the fabric has raised, together with some useful diagnostic information.

diagnostic

Deployement to Azure

You have now crafted a cloud project as a simple ASP.NET web application, but you haven't used any cloud-specific APIs yet. In this section while deployment, you examine the cloud project inside the solution and explore some cloud APIs that you can use for your pages.

Cloud Service Configuration

First of all, create a cloud service from the Azure portal named azHelloWord (it is recommended to keep the name the same for both the cloud service and the Visual Studio cloud service) as in the following:

Cloud Service Configuration

Once the cloud services is created and configured as azHelloWorld properly, it shows its current status as in the following:

Cloud Service

Package Building

Hereafter, create the package or bundle up the Azure cloud service from the Visual Studio IDE itself. Go to Solution Explorer, right over the Azure service and make a package as in the following:

Package

Since the package will be deployed at a cloud service, choose the build configuration as Release.

configuration

Finally, the package will be created and can be seen in the project solution directory. There are two files created, one belongs to the original service and the second contains the necessary configuration file. The Service configuration file (azHelloWorld.Cloud.cscfg) contains the service account name under which the application will be deployed. It is used to define the cloud storage account name and its key using that the cloud storage can be accessed.

solution directory

Uploading of Package

After creating the package, open the Azure development portal and open the cloud service azHelloWorld dashboard. Here, choose New Production Deployment as in the following:

New Production Deployment

In the deployment interface, upload both the cloud service file and the configuration files from the solution BIN folder as in the following:

upload both cloud service file

Testing Cloud Service Live

The uploading process usually takes some time, if everything is correctly configured then the Azure portal will show the successful deployment of the services as in the following:

Testing Cloud Service Live

However, you can ensure the correct installation and configuration of cloud services from the dashboard itself, where it is showing the Running status as in the following:

Running status

Finally, test the cloud service by entering the URL as http://azHelloWorld.cloudapp.net into the browser and it shows the server time with the “Hello World” message as in the following:

Hello World

Reference


Similar Articles