« Using Custom Domains with Windows Azure Services | Main | Cloud Storage Tools »

December 01, 2009

Your First Application for Windows Azure

Creating your first application for Windows Azure is quite easy – Windows Azure Tools for Microsoft Visual Studio will do all the work for you. Here the steps.

Developing Hello Windows Azure Application

  1. Start Visual Studio 2010 (currently in Beta 2) in elevated mode:

    Run as Administrator

    If you start Visual Studio in non-elevated mode you will be prompted to do so later on, when you try to run your application in Development Fabric.
  2. Once Visual Studio 2010 is started select New Project and in the Installed Templates tree on the left, under Visual Basic and Visual C# you will find the option Cloud Service.

    Windows Azure Cloud Service Project

    Select .NET Framework 3.5 from the drop down because currently Windows Azure doesn’t support .NET Framework 4.0. Type the name of the project (HelloWindowsAzure in our case) and click OK.
  3. You are presented with a second dialog box where you can select the type of the role you want to develop. You can select from the following types:
    ASP.NET Web Role
    ASP.NET MVC 2 Web Role
    WCF Service Web Role
    Worker Role
    and CGI Web Role
    All of those can be developed in C# and Visual Basic; Worker Role can also be developed in F#. For our simple application you can select ASP.NET Web Role:

    ASP.NET Web Role  

    You can click on the pencil icon and change the name of the role to something more meaningful like HelloWindowsAzure Web Role for example.
  4. Once you confirm the dialog your project is created and the Default.aspx file is open in the UI. The only thing you need to do is type

    Hello Windows Azure

    Between the <div> opening and closing tags.

    Hellow Windows Azure text

Deploying the Code to Development Fabric

Development Fabric is the local environment that takes care of the deployment of your application and manages the resources for it. Deploying your app is quite easy:

  1. Right click on the project and select Build to make sure your project has no compilation errors

    Build Windows Azure Web Role
  2. Once the project is build select Debug –> Start Without Debugging (or alternatively you can press Ctrl+F5) from the menu bar.

    Run Windows Azure Application

    Of course Visual Studio will build the project once again, launch Development Fabric and submit your application for deployment. You will know when Windows Azure Simulation Environment containing Development Fabric and Development Storage is started when you see the balloon and the icon in the notification area.

    Windows Azure Simulation Environment icon
  3. Your default browser window will be opened automatically and you will see the default page of your application

    Hello Windows Azure
  4. If you are curious you can right-click on the Windows Azure Simulation Environment icon and select Show Development Fabric UI

    Show Development Fabric UI option

    Development Fabric UI gives you details about your application (also called Hosted Service as you already know:)), which will be very useful in the future for debugging.

    Development Fabric UI

Deploying Your Application to the Cloud

Once you are done with the development and testing of your application you may decide to deploy it to the cloud so everybody can see it. Once again this it done quite simple from the Visual Studio UI.

  1. You can right-click on the project and select Publish or alternatively select Build –> Publish from the menu bar

    Publish Windows Azure Applicaiton to the Cloud
    Although not perfect the workflow helps you a little with the deployment of your application. Visual Studio does two things for you:
    • Opens the folder where Windows Azure package (cspkg) and configuration (cscfg) files are in Windows Explorer

      Windows Azure package (cspkg) and configuration (cscfg) files
    • Opens your default browser and loads Windows Azure Developer Portal in it

      Windows Azure Developer Portal
  2. In Windows Azure Developer Portal you need to click on your project and select the New Service link in the upper right corner

    Windows Azure Project
  3. On the next page click on Hosted Services

    Windows Azure Hosted Services 
  4. You need to fill in Service Label and Service Description and click Next

    Hosted Service Properties
  5. On the next page you will be prompted to specify the Public Hosted Service URL that contains the Public Service Name as well as the Hosted Service Affinity Group. You can leave the Affinity Group unchanged because we are not concerned about geo-location for now.

    Hosted Service URL and Affinity Groups
  6. When you click Create your Hosted Service will be created. The Hosted Service hosts your application.

    Empty Hosted Service
  7. Click on Deploy button and on the new page select the Windows Azure package (scpkg) and configuration (cscfg) files using the Browse buttons. Also type a name for your deployment – this name is used for visual clue in the UI.

    Deploying Hosted Service
  8. Once you click Deploy your files get uploaded and then deployed on Windows Azure. Depending on the size of your files and the number of roles it may take several minutes to have the application deployed on Windows Azure.

    Windows Azure Hosted Service deployed
  9. Once the application is deployed you need to click on Run to start it. It will show Ready once it is running.

    Hosted Service in running state
  10. Now you can access your Hello Windows Azure application clicking on the Web Site URL

    Hello Windows Azure in the cloud

Summary

To summarize here is what the above process described:

  • Create Windows Azure Cloud Service project in Visual Studio 2010
  • Create Web Role in the Cloud Service project
  • Modify Default.aspx page in the Web Role
  • Deploy the service to the local Development Fabric
  • Access the local service via the browser
  • Deploy the service to Windows Azure
  • Access the service on Windows Azure via the browser

In the explanations above I used Hosted Service and application interchangeably. The official term in Windows Azure is Hosted Service, and it can contain several Web and Worker roles. Because Web Application is more familiar for Web Developers and we developer simple Web Role I allowed myself the freedom to do that.

TrackBack

TrackBack URL for this entry:
http://www.typepad.com/services/trackback/6a0105356030d9970b012875fc13a6970c

Listed below are links to weblogs that reference Your First Application for Windows Azure:

Comments

Feed You can follow this conversation by subscribing to the comment feed for this post.

Post a comment

Comments are moderated, and will not appear on this weblog until the author has approved them.

If you have a TypeKey or TypePad account, please Sign In