Windows Azure – Developers Guide – Part 2 – Web and Worker Role “Hello world”

8 בפברואר 2011

2 תגובות

In my earlier post I talked about the Windows Azure features for the developer, In this post I will create a Simple “Hello world” Application using the Web and Worker Role.

First thing first , If you haven’t downloaded the Windows Azure SDK and the Windows Azure Tools For Visual studio (We can develop on VS2008 but VS2010 is recommended) please download it Here.

After installing we can create our first Windows Azure Solution :

image

When Prompt choose the ASP.NET and Worker role:

image

You can click on the roles to the right and edit the name of the role, In this demo I Named them WebHello and WorkerHello.

Click OK.

The solution presents us with the Following Projects :

image

FirstAzureProgram – A project that contain all the Configuration of our Roles, we will look into it later in this Walkthrough.

WebHello – A Standard ASP.NET Project , with several new References to Windows Azure Libraries.

WorkerHello – A Standard Library Project that uses the Windows Azure Libraries and has a class that Inherit from RoleEntryPoint and will behave as the “Main” of the project.

Although we haven’t really written any code lets run our Application. Click Ctrl+F5 to run it.

As you can see , we now have the Windows Azure Emulator running and the solution is running on our local computer. Right Click on the Notify-Icon will open the following Context Menu:

 imageimage

Right now we are not using the Storage so click on the “Show Compute Emulator UI”.

image

public class WorkerRole : RoleEntryPoint
  {
    public override void Run()
    {
      Trace.WriteLine("WorkerHello entry point called", "Information");
      while (true)
      {
        Thread.Sleep(10000);
        Trace.WriteLine("Working", "Information");
      }
    }

    public override bool OnStart()
    {
      Trace.WriteLine("Blog Demo ASP.NET Role Started");
      return base.OnStart();
    }
  }

As you can see we can see all the Roles Currently Running and their “Console”, We can use this tool to stop or restart a Role. This is a good time to see that we currently have one instance of every Role running.

This emulator allow us to test and develop Windows Azure Application without using Our Credit Card.

Lets close the Emulator and return to the Solution.

The ASP.NET Project is to much of our surprise a…. ASP.NET Project. Anything we used to do and develop with ASP.NET is exactly the same.

So what is the Big Deal?

Right now… Nothing. There is no Big Deal in this project and it can remain an ordinary ASP.NET Project, In the next Post we will add some Azure related code to take advantage of the fact we are hosted on the cloud.

Lets take a look at the WorkerHello Project and the Following code:

public class WorkerRole : RoleEntryPoint
  {
    public override void Run()
    {
      Trace.WriteLine("WorkerHello entry point called", "Information");
      while (true)
      {
        Thread.Sleep(10000);
        Trace.WriteLine("Working", "Information");
      }
    }

    public override bool OnStart()
    {
      Trace.WriteLine("Blog Demo ASP.NET Role Started");
      return base.OnStart();
    }
  }

We Have the OnStart() Method that is called once when the Role is starting, and the Run() method that run after the OnStart() finishes. Where does the Trace.WriteLine() goes to?

image

If we look again at the Windows Azure Compute Emulator , we can see the trace in the Console.

That is it for this post, In my Next post I will show how to get Information From the Web Role and transfer it to the Worker Role using 2 Storage features, Tables and Queue.

הוסף תגובה
facebook linkedin twitter email

כתיבת תגובה

האימייל לא יוצג באתר. שדות החובה מסומנים *

2 תגובות

  1. Patricia3 בספטמבר 2012 ב 14:24

    Yes it is possible, just add the WCF scvriee (*.svc + scvriee dll) to the ASP.NET project. IIS will be able to serve request for both. Make sure you put the required configuration into your web.config.It is not the only solution but it should be easy to implement.

    הגב
  2. http://bio-oil-reviews.org/9 באפריל 2013 ב 14:43

    We are pretty sure We've read this same form of assertion anywhere else, it ought to be more popular with all the masses.

    הגב