Introduction to Azure Web Roles

facebooktwittergoogle_plusredditpinterestlinkedinmail

Azure Web Roles Feature

Basically Azure Web Role is a web site or a service that is hosted on windows Azure IIS. It supports both HTTP and HTTPS certificates. One of the nice things about web role is, it handles the load balancing automatically. So if we have multiple instance of web role running on Azure, then it automatically balances the traffic among the different instances. Load balancing does not have any concept of session, cookie, etc. so each request routed to a suitable web role instance.

Why we need Azure Web Roles ?

This technology is designed expressly to support scalable, reliable, and low-admin applications and it’s an example of what’s commonly called Platform as a Service (PaaS) . But in the case of Azure Web apps you do not have administrative access , which means that you can’t install arbitrary software.

Create and deploy Web Role


To create a Azure web role, we need the Azure SDK and for deployment we need Azure subscription. If you have these then go to visual studio, create a new project and select cloud services under cloud menu.

Azure Web Role Create

After selecting a project template, one popup will be opened. Here we need to select the type (Web role, worker role etc) of cloud service. Click on Web role and click on the right arrow to add it in the solution.

Azure Web Role Select Type

Azure Web Role - Select MVC Project

Here I change the web role name to Webrole.Web. Then click ok. You will get one more pop up after that, there you need to select the type/ template (MVC/Web API etc.) of the web roll. Select MVC and click ok. It would create a brand new cloud solution for us.

Azure Web Role - Solution

Run the application, then you can see cloud emulator is running on task bar instead of IIS express and you will get the result in the browser.

Azure Web Role - Emulator

Run multiple instances of a single Web Role

Consider cloud service as a group and roles (Worker role/Web Role/VM role) are the different items in the group. Instance is a combination of a Virtual machine , operation system , some software/services etc . Suppose one of your Web role got lots of traffic, however your web role has single instance. The common practice to overcome this situation is to scale up the virtual machine. For scale up, you will have to down your web role and scale up the memory/processing power. There will be a downtime , so it is not a best practice . The best way is to overcome this is to create multiple instance of the same web role and Azure will take care the load balancing. To do this, right click on our web role file which is coming under Roles folder and select properties. There we can change the number of instances and the type of VM, etc. Change the instance count to 2 the after deployment we can see 2 instances in the cloud.

Azure Web Role - Change Instance Count

Deploy Web Role to Azure

Azure deployment is pretty simple and straight forward. Go to Azure service project, right click and publish.

Azure Web Role- Publish first

Enter the publish settings there. Here we need to select one cloud service which is associated with your subscription if you do not have cloud service, then select create a new option from the drop down. Apart from cloud service we need to select the environment, build configuration, service configuration etc.

Azure Web Role - Publish Settings

Then go ahead and click publish.

Azure Web Role - Building

It will take some time to complete.

Azure Web Role - Deployment Success

After the deployment you will be able to access your web role and if you open the server explorer then you can see our 2 instances running on cloud.

Azure Web Role - Server Explorer

The following two tabs change content below.

Tom Mohan

Tom Mohan is a technologist who loves to code and build. He enjoys working on Microsoft Technologies. Tom specializes in ASP.NET MVC, Web API , Azure, C# ,WPF, SQL etc and holds a Bachelor engineering degree in Computer Science. Certification : MCSD , MCTS