Demystifying The Code

Azure Application Part 1: Setup and running “Hello World”

This is part 1 in this series where I am building an Azure shopping cart application from the ground up.  In this post, I will illustrate how to setup your development environment, setup your Azure Services Developer Portal, including the process of requesting a token.  I will then build out a simple hello world example, run it in the development fabric, debug it and finally publish it to the cloud.  If you are already familiar with these topics and are already set up, please feel free to go directly to part II (if it is published).

 

Watch the Screencast

Setting Up Your Environment

As I mentioned, the first few posts of this series deal strictly with Windows Azure offerings (we will be working with .NET Services and Sql Data Services in later posts).  This greatly simplifies setting up our development environment.  For this post, I will limit the setup information to what is necessary for Windows Azure.  As I delve into other areas, I will provide the necessary setup info.

 

Development Environment

A great thing about working with Windows Azure is that we have a simulated environment for you for development and testing.  We simulate both the Windows Azure Fabric, as well as Windows Azure Storage on you local machine so you are able to build and test applications taking advantages of these services without deploying to or accessing the cloud.  All you need to do is to install the following:

You can go here to see details about pre-requisites for the SDK, but for your convenience, I have summarized below:

  • Operating System
    • (for x86 version of SDK) – 32-bit editions of Windows Vista SP1 or Windows Server 2008.
    • (for x64 version of SDK) – 64-bit edition of Windows Vista® SP1 or Windows Server® 2008
  • .NET Framework 3.5 sp1
  • Sql Server
  • Internet Information Services (IIS) 7.0 must be enabled, with ASP.NET and Windows Communication Foundation (WCF) HTTP Activation – Click here for details how to configure

The prerequisites for the Visual Studio tools include everything above plus:

 

Set Up Your Windows Azure Account

With your development environment set up, you have everything you need to get started developing our Azure store sample application.  However, you might want to actually deploy this code to the cloud.  For that you are going to need an Azure account.  We are currently in CTP, so there is no charge for this account (that will chance when we go to release).  You do, however, need a token.

To Request A Token:

  1. Navigate to www.microsoft.com/azure.  Click on Try It Now
    image
  2. Click on Try It Now to register with Connect and Request a Token
    image
  3. Log In with your Windows Live ID (you will need to create an account if you don’t already have one)
    image
  4. You will then have to complete the registration information (no screenshot required)
  5. Click on the connection directory tab
    image
  6. Scroll until you see Azure Service Invitations
    image
  7. You are registered and should see a page like this:
    image

 

To Setup Your Azure Services Developer Portal

  1. Navigate to https://lx.azure.microsoft.com
  2. Log In with your live id
  3. Fill in your country and lanugage and press I Agree to create a new account
    image
  4. You will be re-directed to a confirmation page.  Press continue
    image
  5. You will be redirected to a page where you can redeem your invitation token.  This token is necessary to create a Hosted Services project, as well as a Storage project.  Don’t worry about closing the page or pressing cancel.  You will be re-directed here the next time you log in.  As I annotated below, you may have to wait a bit to receive your token (i.e. don’t proceed directly to Outlook and continually press refresh until you receive it).  We are in CTP and have a limited number of tokens to hand out at any given time.
    image
  6. Once you have your token entered appropriately, you will no longer see this page.  You will instead be re-directed to a page in the portal where you can create a project.  Here is what you would see if you chose ‘Cancel’ on the previous page or if you click the ‘New Project’ link under the ‘Summary Tab’.
    image
  7. Here is the view you would see if you had entered a valid token:
    image
  8. You are now ready to create your Hosted Services Project.  Click on ‘Hosted Services’ to add a new Hosted Services project.
  9. On the next page, enter the following information:
    • Project Label – Enter a label for your Hosted Services project.  This label will be exposed on the Azure Services Developer Portal
    • Project Description – Enter a description of the project you will be hosting

    image

  10. On the next page, enter a service name – a unique service / domain name to create the unique DNS name.  You can check on the availability of service names.  After you have settled on a unique service name, press the ‘Create’ button.
    image
  11. Your project is now created and you are ready to deploy a solution.  We will get to that later.

* You can also take a look at the How Do I: Get Started Developing with Windows Azure? and the How Do I: Deploy a Windows Azure Application? screencast for walkthroughs on getting started with Windows Azure and deploying a Windows Azure Application.

 

Creating our Cloud Project in Visual Studio

Assuming that you set up your development environment as described above, you are ready to create your Cloud project.  In this part, we are going to create a “Hello World” web application, test it on the local development fabric and deploy it to the cloud.  In part II, we will access data from Azure Table Storage.  While you can also use Visual Web Developer Express, I am going to be using Visual Studio.  Let’s get started:

 

Create the Cloud Project

  1. Choose File > New > Project from the Visual Studio Menu
  2. Choose Cloud Service > Web Cloud Service
    image
  3. That’s it!

 

What was created?

It is kind of funny how I sometimes view project templates.  I almost assign some kind of magical value to them – like they just created life – when in reality, they are just templates.  They set up project files, add appropriate code files and set up config appropriately.  Perhaps I assign the magical value in the fact that it is so hard to create a good project template.  That should change with future versions of VS.  Anyhow, I digress.  The template created 2 projects.  The goals of these projects are as follows:

A Cloud Service Project

  • Allows you to build and package your cloud application to run in the local development fabric
  • Allows you to debug your cloud application in the local development fabric
  • Allows you to build and package your cloud application to deploy to the cloud
  • Stores configuration settings that apply to all instances of each role
  • Allows you to configure the number of instances to be created for each role

A Web Role

A web role in this template is really just an ASP.NET application.  We have created additional web role projects, including a Cgi Web Role which allows you to host PHP and Ruby apps.  This template, however creates an ASP.NET application.

 

Add Some Code

  1. Add a label to Default.aspx, giving it an ID and setting runat=”server”.
    image
  2. Add some code to Default.aspx.cs that executes on the server that sets the text of the label.  It doesn’t matter what you put here, we just want to illustrate that the server is doing some work and this is not simply a static page.
    image 

 

Run In The Development Fabric

Run It

Press F5 or the Start Debugging button to run the application in the development fabric.  Here is the result:

image

What Happened

The Visual Studio tool do some nice work for you.  Here is what happens.

  • Visual studio created a Windows Azure Service Package.  This is the same package that is used to deploy to the web.  However, in that instance, the package is zipped and encrypted.  When running in the local development fabric, the extension of the package is csx and if you are running with debug symbols, you will find this in the debug directory. (See this post by Jim Nakashima for more information on how the service package is created)
    image
  • VS ensures that development storage is started
  • VS ensures that the development fabric is started and deploys your package to the fabric (CSRun is the exe that does this)
  • If you are running with debug symbols, Visual Studio will attach the debugger to a role running in the development fabric

(See this documentation for more information on the development fabric)

Debug It

Set a breakpoint on our code that sets the text of the label and start with debugging.  Here is what you see:

image

It is that easy to debug our applications.  Please note that it is not possible to attach a debugger to instances running in the cloud.  For those situations, you need to use logging appropriately.  We will cover that in future posts.

 

Deploy Our Application To The Cloud

* This section assumes that you have created a Windows Azure account, received your token and redeemed your invitation token as detailed above.  It also assumes that you have created a Hosted Services project.  I will use the token <accountName> to represent the label for the account.

 

Remember that when we publish to the cloud, we are packaging the application in the exact same way as when we are running it in the development fabric.  The only difference is that the file is zipped and encrypted.  Oh, and it has a different extension.

Here is the process to deploy to the cloud:

  1. (optional) Set the application id in the project properties from your Hosted Service Application ID
    • Copy the application id from the Hosted Service Project to the clipboard
      image
    • Right-Click on the cloud services project (AzureStore) > Properties > Portal
    • Paste the application id
      image
  2. Right-Click on the cloud services project (AzureStore) > Publish
    image
  3. A browser will be launched and it will automatically navigate you to the appropriate project if you completed step 1.  Otherwise, navigate to the Hosted Service project where you want to deploy.  An explorer window also opened to the location where the cspkg (encrypted, zipped project) and the cscfg files are.
  4. Click on the Deploy button under Staging
    image
  5. Click on the Browse buttons and navigate to the publish directory under your project.  It is the directory the explorer opened to.
    image
  6. Click Deploy.  This process may take a few minutes.
  7. Press Run.  This process may also take a few minutes.
  8. When the WebRole reads ‘Running’, you are ready to test.
  9. Click on the ‘Web Site Url’ link.
    image
  10. That is it, you are running in the cloud!  You are in staging, but feel free to swap it to production.
    image

 

In my next post, I will set up Azure Table Storage.  I will create our Wine table for the catalog, write some code to add wines and fetch wines.  I will then write some simple aspx pages to consume that code.  Lastly, I will target the cloud instead of the local development environment.  Until then…

Speak Your Mind

Tell us what you're thinking...
and oh, if you want a pic to show with your comment, go get a gravatar!

Demystifying The Code