Introducing Windows Azure – Creating your first ASP.NET Web Role Project

Posted by: Mahesh Sabnis , on 4/17/2012, in Category Windows Azure
Views: 95642
Abstract: Windows Azure provides a comprehensive platform for developing Scalable, High available application. With the Visual Studio 2010 templates, any .NET developer can easily develop applications for the cloud. In this article, we will introduce Azure and see how to create an ASP.NET Web Role Project

All of us who are responsible for developing high scalable, high available applications are very well aware of the infrastructure challenges. To achieve scalability and availability of the applications, we require high capability servers, high bandwidth network and dedicated infrastructure. This type of infrastructure adds significant cost overhead for all critical SLA based applications.

Today, we have a simple answer to these challenges - move such applications and their infrastructure to the Cloud!

Now the question is, before the Cloud, what was the situation? The answer is to have an On-Premises Server Infrastructure. This type of infrastructure is generally used by most of the big players in the industry to store, maintain and manage their data. Having this kind of infrastructure helps an organization in the following ways:

  • Since the data is locally available in their premises, they need not worry about ‘tenancy’ of data. The data is in self owned data centers.
  • At any point of time, companies can add new hardware, change software as per their business requirements.

However, there are some practical limitations and challenges in this infrastructure:

  • Such high performance infrastructure requires a dedicated maintenance and support team. This increases financial cost.
  • Since companies need to manage servers, the power consumption by the infrastructure increases cost of maintenance.
  • Any hardware failure can create problems of application availability and sometimes it is a challenge to rectify these failures.
  • To make data of the application available across various locations of the world, a company needs to implement data replication across various locations, which is non-trivial.

The above challenges can be broadly categorized into two buckets:

a. Cost

b. Skills

Introducing Windows Azure

Windows Azure is a cloud-based platform from Microsoft that aims to take the infrastructure challenges away from companies and provide a cost-effective way for hosting and maintaining demanding applications.

We as developers, must think about common applications that require scalability, high availability etc and some examples are listed below:

- Web Sites

  • SLA (Service Level Assurance) based service applications like source control (GitHub, Bitbucket), Media streaming (Netflix), CRM (Sales Force)
  • Online shopping based sites (like Amazon, Flipkart etc)

- Application that require clusters of high performance computers for adhoc CPU intensive computation.

- Global accessible WEB APIs.

- High traffic Social Sites.

 

What is the Windows AZURE platform?

Windows Azure is an operating system for the cloud. It provides a complete abstraction layer over the physical components of the system. It is responsible for managing the application hosted by the customer (or a developer). It provides scalability and fault-tolerance for the application developed by the customer. It provides load balancer and data replication so that the data will be always available.

Windows Azure provides complete virtual environment with abstracts set of servers. This provides a common platform for building application and services. Although as a developer you work with these servers, but you are not responsible for installing any software on it and although you deploy your application on it, you do not know where does your software get installed.

Windows Azure provides the below advantages to the developer:

  • No hardware configuration or installation by the developer.
  • No network or firewall configuration.
  • Not required to apply updates, patches or bother about hardware or software issues.

Azure is a Subscription based Cloud Platform!

Note: As a developer, you have to purchase a subscription for deploying an application to the cloud. Please visit www.azure.com for further details about the subscription, costing etc.

 

Services offered by Azure

The Azure Cloud offers the following core services:

azure-core-services

Let’s quickly study these services one by one

Compute

  • This provides the number of instances required to manage the application. Here instances mean the virtual machines required for scaling the application.
  • In the Azure SDK tools, Windows Azure Compute emulator provides simulation of your application before deployment of the application on the Cloud.
  • The number of instances requirement for the application is specified in the configuration file of your cloud project.
  • It provides Web Role, Worker Role.

Worker Role:

  • It is a general purpose host for executing the code.
  • Provides Run() method for executing the hosting code.
  • It is more similar to Windows Service and hence used for background Operations.

Web Role:

  • It provides all features of the Worker role. Typically it is designed for making Web Sites or services accessible over Http.
  • It also provides features of IIS 7.x.
  • One Web Role can contain multiple Web Sites or services in it.

This simple diagram given below explains the possible input required for compute:

azure-compute-requirements

The diagram above contains the following components:

The Service definition (.csdef) file defines the number instances required for the application, the default value is 1. You can change the value as per your requirements.

Note: More the instances, more the bill you need to pay.

The Service configuration file contains the service account name under which the application will be deployed. Here you get two service configuration files as shown below:

  • ServiceConfiguration.Cloud.cscfg  -  used to define the cloud storage account name and its key using which the cloud storage can be accessed.
  • ServiceConfiguration.Local.cscfg - contains Local storage by default which you get using Windows Azure SDK.

The Source code is the .NET language business logic which you write in the application.

The application deployment package to upload to the Windows Azure portal, where Compute service allocates the necessary instances and provides an access of the storage.

Storage

  • It provides a facility to maintain data published by the user in the storage.
  • The storage provides easy to use REST APIs and Storage client library for accessing storage in the client application.
  • The StorageClient library is a managed .NET abstraction over REST APIs because they are easy to use.
  • User can create a globally unique name. Storage account names are specific data centers provided by AZURE.

Following are the types of storage provides:

  • Blobs - This is typically a file system in the cloud. It is used to store Images, documents, audio and video files etc.
  • Tables  - These are not database tables, instead they are highly scalable structured storage. These help to store entity data.
  • Queue - Conceptually similar to MSMQ and is used to provide Reliable storage and delivery of the messages.
  • Drives - This is a Durable NTFS volume for Windows Azure applications. Typically Blobs makes use of this.

Database

  • This is a SQL Server Database over cloud.
  • This is more similar to SQL Server Management studio. It provides a facility to create database, tables.
  • SQL Server database technology is delivered as a service on the Windows Azure platform.
  • It is more ideal for simple and complex database operation applications e.g. Simple ADO.NET Code, ADO.NET Entity Framework etc.
  • Azure provides SQL Azure management portal where you can create a  SQL Server Database.

 

Building a Simple Azure based Application

Visual Studio 2010 provides a template to create a Cloud project with Simple Web Role. Let us see the steps involved.

Step 1: Open VS2010 and create a new cloud project as shown below:

new-cloud-project

This action opens up the ‘New Windows Azure Project’ window

new-azure-project

Step 2: Select ASP.NET Web Role and click on the right arrow in the window, as shown below:

select-web-role

Click on ‘OK’. An ASP.NET project with a Web Role project will be created as shown below:

web-role-project

Step 3: Click on the ‘ServiceDefination.cscfg’. You will see the following XML:

<?xml version="1.0" encoding="utf-8"?>
<ServiceDefinition name="MyFirstApp"
xmlns="http://schemas.microsoft.com/ServiceHosting/2008/10/ServiceDefinition">
  <WebRole name="WebRole1" vmsize="Small">
    <Sites>
      <Site name="Web">
        <Bindings>
          <Binding name="Endpoint1" endpointName="Endpoint1" />
        </Bindings>
      </Site>
    </Sites>
    <Endpoints>
      <InputEndpoint name="Endpoint1" protocol="http" port="80" />
    </Endpoints>
    <Imports>
      <Import moduleName="Diagnostics" />
    </Imports>
  </WebRole>
</ServiceDefinition>

The above xml shows that the ‘small’ virtual machine will be used to execute the application. It also specifies the protocol and the port used for the communication. You can change these values as per the requirements of the application.

Step 4: Open ServiceConfiguration.Local.cscfg file. The following XML will be displayed:

<?xml version="1.0" encoding="utf-8"?>
<ServiceConfiguration serviceName="MyFirstApp"
xmlns="http://schemas.microsoft.com/ServiceHosting/2008/10/ServiceConfiguration"
osFamily="1" osVersion="*">
  <Role name="WebRole1">
    <Instances count="1" />
    <ConfigurationSettings>
      <Setting name="Microsoft.WindowsAzure.Plugins.Diagnostics.ConnectionString"
    value="UseDevelopmentStorage=true" />
    </ConfigurationSettings>
  </Role>
</ServiceConfiguration>

The above xml file shows that the instance used will be 1 and it uses the local development storage for storing Blob, Table etc. using the setting UseDevelopmentStorage=true. During the actual production deployment of the application over cloud, you will need to make use of ServiceConfiguration.Cloud.cscfg where you need to specific the Storage Account Name and the access key provided to the access of the Storage.

Step 5: Run the application using F5 and you will find the Windows Azure Compute Emulator will start as shown below:

azure-emulator

Right click on it and select ‘Show Compute Emulator UI’. The Emulator will show the instances running as shown below:

azure-computer-emulator

Here since the Instance in .cscfg is 1, that’s why the Web Role ‘0’ is shown. Also right click on it and select ‘Show Storage Emulator UI’, the Emulator will show the Storage running as shown below

storage-emulator

The Emulator UI helps you to diagnose the application and check whether the storage is accessible are not. Check if everything’s fine and deploy the application on cloud.

Conclusion: Windows Azure provides a comprehensive platform for developing Scalable, High available application. With the Visual Studio 2010 templates, any .NET developer can easily develop applications for the cloud.

Give a +1 to this article if you think it was well written. Thanks!
Recommended Articles


Page copy protected against web site content infringement by Copyscape


User Feedback
Comment posted by S.Muthukumaramani on Wednesday, April 18, 2012 5:24 AM
very nice
Comment posted by Mahesh Sabnis on Thursday, April 19, 2012 1:08 AM
Hi Muthukumaramani,
  Thanks a lot. There is yet more to go.
Thanks
Regards
Mahesh Sabnis
Comment posted by Ravindra Kumar on Thursday, April 19, 2012 1:17 AM
very nice article and I like this article because it shows figure also.
Comment posted by Mahesh Sabnis on Thursday, April 19, 2012 11:49 PM
Hi Ravindra Kumar,
Thanks a lot. Soon you will find on Storage Starts from BLOB.
Regards
Mahesh Sabnis
Comment posted by Praveen on Wednesday, April 25, 2012 7:43 AM
HI
   can you please tell be the beset book to start Windows Azure

Regards
Praveen
Comment posted by Mahesh Sabnis on Saturday, June 23, 2012 6:07 AM
Hi Praveen,

  Bet you read MSDN. www.azure.com
Regards
Mahesh Sabnis

Post your comment
Name:  
E-mail: (Will not be displayed)
Comment:
Insert Cancel