DOCX

Introduction to Windows Azure development in VS2010

By Martha Marshall,2014-09-20 15:17
15 views 0
Introduction to Windows Azure development in VS2010

Hands-On Lab

    Introduction to Windows Azure

Lab version: 2.0.0

    Last updated: 9/20/2011

    Page | 1

CONTENTS

    OVERVIEW ............................................................................................................................................. 3

    EXERCISE 1: BUILDING YOUR FIRST WINDOWS AZURE APPLICATION .......................................... 5

    Task 1 Creating the Visual Studio Project ....................................................................................... 6

    Task 2 Creating a Data Model for Entities in Table Storage .......................................................... 11

    Task 3 Creating a Web Role to Display the Guest Book and Process User Input ........................... 24

    Task 4 Queuing Work Items for Background Processing .............................................................. 34

    Verification .................................................................................................................................... 38

    EXERCISE 2: BACKGROUND PROCESSING WITH WORKER ROLES AND QUEUES ...................... 44

    Task 1 Creating a Worker Role to Process Images in the Background ........................................... 44

    Verification .................................................................................................................................... 54

    EXERCISE 3: DEPLOYING A WINDOWS AZURE APPLICATION ....................................................... 56

    Task 1 Creating a Storage Account and a Hosted Service Component .......................................... 56

    Task 2 Deploying the Application to the Windows Azure Platform Management Portal ............... 64

    Task 3 Configuring the Application to Increase the Number of Instances ..................................... 71

    Task 4 Testing the Application in the Staging Environment .......................................................... 74

    Task 5 Promoting the Application to Production.......................................................................... 75 SUMMARY ............................................................................................................................................ 78

    Page | 2

Overview

    A service hosted in Windows Azure consists of one or more web roles and worker roles. A web role is an ASP.NET Web application accessible via an HTTP or HTTPS endpoint and is commonly the front-end for an application. Worker roles are background-processing applications and are typically found in the back-end. Windows Azure services may be comprised of one or both types of roles and can run multiple instances of each type. Role instances can be added or removed based on demand and allow applications to quickly and economically scale-up or down when the need arises.

    Windows Azure storage services provide storage in the cloud, which includes Blob services for storing text and binary data, Table services for structured storage that can be queried, and Queue services for reliable and persistent messaging between services.

    In this hands-on lab, you will explore the basic elements of a Windows Azure service by creating a simple GuestBook application that demonstrates many features of the Windows Azure platform, including web and worker roles, blob storage, table storage, and queues.

    In the GuestBook application, a web role provides the front-end that allows users to view the contents of the guest book and submit new entries. Each entry contains a name, a message, and an associated picture. The application also contains a worker role that can generate thumbnails for the images that users submit.

    When users post a new item, the web role uploads the picture to blob storage and creates an entry in table storage that contains the information entered by the user and a link to the blob with the picture. The web role renders this information to the browser so users can view the contents of the guest book. After storing the image and creating the entry, the web role posts a work item to a queue to have the image processed. The worker role fetches the work item from the queue, retrieves the image from blob storage, and resizes it to create a thumbnail. Using queues to post work items is a common pattern in cloud applications and enables the separation of compute-bound tasks from the front-end. The advantage of this approach is that front and back ends can be scaled independently. Objectives

    In this hands-on lab, you will learn how to:

    ; Create applications in Windows Azure using web roles and worker roles

    ; Use Windows Azure storage services including blobs, queues and tables

    ; Deploy an application to Windows Azure

    Page | 3

    Note: For a more advanced scenario based on the GuestBook application that shows how to deal with poison messages in Azure queues and how to design an Azure role to make use of plug-in components that can be dynamically loaded, see the Asynchronous Workload Handling lab in this training kit.

Prerequisites

    The following is required to complete this hands-on lab:

    ; IIS 7 (with ASP.NET, WCF HTTP Activation)

    ; Microsoft Visual Studio 2010

    ; Microsoft .NET Framework 4.0

    ; Windows Azure Tools for Microsoft Visual Studio 1.4

    ; SQL Server 2005 Express Edition (or later)

Setup

    For convenience, much of the code used in this hands-on lab is available as Visual Studio code snippets. To check the prerequisites of the lab and install the code snippets:

    1. Open a Windows Explorer window and browse to the lab’s Source\Setup folder.

    2. Double-click the Dependencies.dep file in this folder to launch the Dependency Checker tool

    and install any missing prerequisites and the Visual Studio code snippets.

    3. If the User Account Control dialog is shown, confirm the action to proceed.

Note: This process may require elevation. The .dep extension is associated with the Dependency

    Checker tool during its installation. For additional information about the setup procedure and how to install the Dependency Checker tool, refer to the Setup.docx document in the Assets folder of the

    training kit.

Using the Code Snippets

    Throughout the lab document, you will be instructed to insert code blocks. For your convenience, most of that code is provided as Visual Studio Code Snippets, which you can use from within Visual Studio 2010 to avoid having to add it manually.

    Page | 4

    If you are not familiar with the Visual Studio Code Snippets, and want to learn how to use them, you can refer to the Setup.docx document in the Assets folder of the training kit, which contains a section

    describing how to use them.

    Exercises

    This hands-on lab includes the following exercises:

    ; Building Your First Windows Azure Application

    ; Background Processing with Worker Roles and Queues

    ; Deploying a Windows Azure Application

Estimated time to complete this lab: 60 minutes.

    Note: When you first start Visual Studio, you must select one of the predefined settings collections. Every predefined collection is designed to match a particular development style and determines window layouts, editor behavior, IntelliSense code snippets, and dialog box options. The procedures in this lab describe the actions necessary to accomplish a given task in Visual Studio when using the General Development Settings collection. If you choose a different settings collection for your development environment, there may be differences in these procedures that you need to take into account.

    Exercise 1: Building Your First Windows Azure Application

    In this exercise, you create a guest book application and execute it in the local development fabric. For this purpose, you will use the Windows Azure Tools for Microsoft Visual Studio to create the project using the Cloud Service project template. These tools extend Visual Studio to enable the creation, building and running of Windows Azure services. You will continue to work with this project throughout the remainder of the lab.

    Note: To reduce typing, you can right-click where you want to insert source code, select Insert Snippet, select My Code Snippets and then select the entry matching the current exercise step.

    Page | 5

    Task 1 Creating the Visual Studio Project

    In this task, you create a new Cloud Service project in Visual Studio. 1. Open Visual Studio as administrator from Start | All Programs | Microsoft Visual Studio 2010

    by right clicking the Microsoft Visual Studio 2010 shortcut and choosing Run as administrator.

    2. If the User Account Control dialog appears, click Continue.

    3. From the File menu, choose New and then Project.

    4. In the New Project dialog, expand the language of your preference (Visual C# or Visual Basic) in

    the Installed Templates list and select Cloud. Choose the Windows Azure Project template, set

    the Name of the project to GuestBook, set the location to Ex1-

    BuildingYourFirstWindowsAzureApp\[CS|VB] in the Source folder of the lab, change the

    solution name to Begin, and ensure that Create directory for solution is checked. Click OK to

    create the project.

    Figure 1

    Creating a new Windows Azure Cloud Service project (C#)

    Page | 6

Figure 2

    Creating a new Windows Azure Cloud Service project (Visual Basic)

    Note: Windows Azure supports the .NET Framework 4.0. If you use Visual Studio 2010 to create the project, you can select this version for the target framework and take advantage of its new features.

    5. In the New Windows Azure Project dialog, inside the Roles panel, expand the tab for the

    language of your choice (Visual C# or Visual Basic), select ASP.NET Web Role from the list of

    available roles and click the arrow (>) to add an instance of this role to the solution. Before closing the dialog, select the new role in the right panel, click the pencil icon and rename the role as GuestBook_WebRole. Click OK to create the cloud service solution.

    Page | 7

Figure 3

    Assigning roles to the cloud service project (C#)

Figure 4

    Assigning roles to the cloud service project (Visual Basic)

    Page | 8

    6. In Solution Explorer, review the structure of the created solution.

    Figure 5

    Solution Explorer showing the GuestBook application (C#)

    Page | 9

Figure 6

    Solution Explorer showing the GuestBook application (Visual Basic)

    Note: The generated solution contains two separate projects. The first project, named GuestBook, holds the configuration for the web and worker roles that compose the cloud application. It includes the service definition file, ServiceDefinition.csdef, which contains

    metadata needed by the Windows Azure fabric to understand the requirements of your application, such as which roles are used, their trust level, the endpoints exposed by each role, the local storage requirements and the certificates used by the roles. The service definition also establishes configuration settings specific to the application. The service configuration file, ServiceConfiguration.cscfg, specifies the number of instances to run for each role and sets the value of configuration settings defined in the service definition file. This separation between service definition and configuration allows you to update the settings of a running application by uploading a new service configuration file.

    The Roles node in the cloud service project enables you to configure what roles the service includes (web, worker or both) as well as which projects to associate with these roles. Adding and configuring roles through the Roles node will update the ServiceDefinition.csdef and

    ServiceConfiguration.cscfg files.

    The second project, named GuestBook_WebRole, is a standard ASP.NET Web Application

    project template modified for the Windows Azure environment. It contains an additional class

    Page | 10

Report this document

For any questions or suggestions please email
cust-service@docsford.com