02-Article Introduction to Windows Azure

Embed Size (px)

Citation preview

  • 7/30/2019 02-Article Introduction to Windows Azure

    1/19

    http://msdn.microsoft.com/rampup

    http://msdn.microsoft.com/rampup

    Getting Started with the Windows Azure Tools for Visual

    Studio

    Windows Azure Platform

    Updated: November 22, 2010

    This walkthrough will guide you through using the Windows Azure Tools for Microsoft Visual Studio to create a

    new Windows Azure Application, run and debug it locally, deploy it to the cloud, and debug it with IntelliTrace

    while it is running on Windows Azure.

    Installing the Windows Azure Tools for Microsoft VisualStudio 2010

    This step assumes that you have not yet installed the Windows Azure Tools for Microsoft Visual Studio 2010. If

    you have already installed the Windows Azure Tools, proceed to the next section.

    1. Click on the File | New | Project menu, browse to either the Visual Basic or Visual C# node, and select

    the cloud service node that contains a project template named Enable Windows Azure Tools.

    Formatted: Bullets and Numbering

  • 7/30/2019 02-Article Introduction to Windows Azure

    2/19

    http://msdn.microsoft.com/rampup

    http://msdn.microsoft.com/rampup

    2. After creating the project, the template will direct you to download the Windows Azure Tools in order to

    continue. This guarantees that youll be using the latest version of the tools and SDK that support the

    latest version of Windows Azure.

    Note

    Windows Azure Tools requires IIS7 or later. To install IIS, use the Microsoft Web Platform Installer.

    Formatted: Bullets and Numbering

    http://www.microsoft.com/webhttp://www.microsoft.com/web
  • 7/30/2019 02-Article Introduction to Windows Azure

    3/19

    http://msdn.microsoft.com/rampup

    http://msdn.microsoft.com/rampup

    Creating a Windows Azure Application

    To create a new Windows Azure Application:

    1. Start Visual Studio 2010 as an administrator.

    2. Create a new project (File | New | Project).

    3. In the C# and VB project templates, notice the new Cloud template type. Select the Windows Azure

    Project template. Choose the target framework - both .NET Framework 4 and .NET Framework 3.5 are

    supported.

    4. Give the project a name and hit OK.

    5. Add a Web Role to the solution by selecting the ASP.NET Web Role item and clicking the right arrow.

    You can add multiple Web and Worker roles to your Windows Azure solution.

    6. Rename WebRole1 to MyWebRole by clicking on the edit button on the right side of the item. The

    edit button will appear on mouse over. Click OK.

    You should have a solution with two projects:

    A Windows Azure project

    A Web Role which is an ASP.NET web application

    The Solution Explorer will look similar to the following image:

    Formatted: Bullets and Numbering

    Formatted: Bullets and Numbering

  • 7/30/2019 02-Article Introduction to Windows Azure

    4/19

    http://msdn.microsoft.com/rampup

    http://msdn.microsoft.com/rampup

    Add code to the Web Role Project

    Modify the Web Role Project using the following procedure:

    1. Open Default.aspx and switch to design view.

    2. Open the Toolbox and double-click the Button tool to add a button to the page. Double-click the new

    button on the page to add an event handler.

    3. In the event handler, add code that will upload some text to the Blob service. Start by adding

    these using statements to bring in some Windows Azure types:

    Copy

    using Microsoft.WindowsAzure;

    using Microsoft.WindowsAzure.StorageClient;

    using Microsoft.WindowsAzure.ServiceRuntime;

    4. Add code to create a CloudStorageAccount instance from a connection string in the configuration

    settings, create a blob container, upload a text blob to that container and write a log message.

    Copy

    protected void Button1_Click(object sender, EventArgs e)

    {

    // Setup the connection to Windows Azure Storage

    var storageAccount =

    CloudStorageAccount.Parse(RoleEnvironment.GetConfigurationSettingValue("MyConnectionS

    tring"));

    var blobClient = storageAccount.CreateCloudBlobClient();

    // Get and create the container

    Formatted: Bullets and Numbering

    Formatted: Bullets and Numbering

    Formatted: Bullets and Numbering

  • 7/30/2019 02-Article Introduction to Windows Azure

    5/19

    http://msdn.microsoft.com/rampup

    http://msdn.microsoft.com/rampup

    var blobContainer = blobClient.GetContainerReference("quicklap");

    blobContainer.CreateIfNotExist();

    // upload a text blob

    var blob = blobContainer.GetBlobReference(Guid.NewGuid().ToString());

    blob.UploadText("Hello Windows Azure");

    // log a message

    System.Diagnostics.Trace.WriteLine("Added blob to Windows Azure Storage");

    }

    5. Add a breakpoint to the line of code you just added in the Button1_Click event handler.

    Note

    As part of the role templates, a Windows Azure trace listener is added to the web.config. The trace listener will route trace and debug

    messages to the Windows Azure Diagnostics system.

    Building and Debugging the Windows Azure Application

    1. Build the project by right clicking on the Windows Azure project and selecting Build.

    2. To see the build output, right-click the Windows Azure project and select Open Folder in Windows

    Explorer. Drill into the bin\debug directory to see the build output. The .csx folder is a version of the

    service package that runs on the Windows Azure compute emulator.

    Formatted: Bullets and Numbering

    Formatted: Bullets and Numbering

  • 7/30/2019 02-Article Introduction to Windows Azure

    6/19

    http://msdn.microsoft.com/rampup

    http://msdn.microsoft.com/rampup

    Modifying the Number of Role Instances to Run

    1. Select a role under the Roles node in the Solution Explorer, right click and select Properties.

    This will display the property pages for the web role. Every role-level element and attribute in the service

    definition and service configuration files can be edited using the property pages.

    Formatted: Bullets and Numbering

  • 7/30/2019 02-Article Introduction to Windows Azure

    7/19

    http://msdn.microsoft.com/rampup

    http://msdn.microsoft.com/rampup

    2. Change the instance count from 1 to 2.

    3. Click on the Settings tab. Click on Add Setting and add a setting with the name MyConnectionString

    and the value UseDevelopmentStorage=true to configure Visual Studio to use the local storage

    emulator.

    4. At the end of this walkthrough when you are ready to deploy to Windows Azure, you can use this tab to

    change this connection string to use a Windows Azure storage account.

    Debug the Project

    1. Select Debug -> Start Debugging (F5).

    2. Note that a Windows Azure icon is available in the system tray that allows you to show the compute

    emulator UI and the storage emulator UI, or to shutdown those services.

    3. If you click Show Compute Emulator UI, the compute emulator utility appears. You can use this utility to

    manage your local deployments and view log data for them.

    4. The trace message you log in the button push will show up in the log window for the instance that

    services the request as well as the output window in Visual Studio.

    Formatted: Bullets and Numbering

    Formatted: Bullets and Numbering

  • 7/30/2019 02-Article Introduction to Windows Azure

    8/19

    http://msdn.microsoft.com/rampup

    http://msdn.microsoft.com/rampup

    5. If this is your first time using storage emulator, the storage emulator initialization dialog will be displayed.

    6. Hit OK to dismiss when the initialization is complete.

    7. Your browser will start up automatically, pointing to your web site. The full address will be similar to

    http://127.0.0.1:81/default.aspx.

    8. When you click the button, you will hit the breakpoint that you set in the debugger.

    9. Look at the compute emulator UI to see your message in the trace log.

    10. Note that there are two instances because we set the instance count to 2 for the role. Either instance can

    process the request.

    Formatted: Bullets and Numbering

  • 7/30/2019 02-Article Introduction to Windows Azure

    9/19

    http://msdn.microsoft.com/rampup

    http://msdn.microsoft.com/rampup

    11. If you are using the storage emulator, you can right click on the Windows Azure tray icon and select Show

    Storage Emulator UI to bring up the following dialog, which will allow you to control the running storage

    services as well as reset all data.

    Formatted: Bullets and Numbering

  • 7/30/2019 02-Article Introduction to Windows Azure

    10/19

    http://msdn.microsoft.com/rampup

    http://msdn.microsoft.com/rampup

    Browsing the Windows Azure Storage in the Server Explorer

    1. Now that youve added a blob to blob storage, open Server Explorer and expand theWindows Azure

    Storage | (Development) node.

    2. Double-click on the quicklap container to view the blob that was added. Double-click the blob to open

    up the text file in Visual Studio.

    3. Open the Windows Azure Activity Log window. The activity log allows you to track the status of long-

    running operations. You will see an entry corresponding to the text blob you downloaded.

    Publishing the Windows Azure Application

    1. The pre-requisite for this section is that you have a Windows Azure subscription with at least one hosted

    service and one storage account. See the Windows Azure offers page for more information.

    2. Select your role under the Roles node in the Solution Explorer. Right-click and select Properties. Switch

    to the Settings tab and click on the button to the right of the MyConnectionString string.

    3. Click Enter Storage Credentials. Enter an account name and account key for a Windows Azure storage

    account you have created through the Windows Azure Platform Management Portal. Click View on

    the Primary Access key field to get the account key. The key should be a longer form than a GUID, for

    example,

    rLUK5iCkeeA7+2P7LIq0deZ+INAWEI6jRPwCTaep/k9+NRqMQb0Ofy/taAdgDR1/+DtI1rvsa1qBueesHmeQ6

    A==

    4. Press F5 to run the hosted service on the compute emulator to ensure that the storage connection stringwas entered correctly.

    5. Right-click on the Windows Azure project node and select Publish.

    Formatted: Bullets and Numbering

    Formatted: Bullets and Numbering

    Formatted: Bullets and Numbering

    http://www.microsoft.com/windowsazure/offers/http://windows.azure.com/http://windows.azure.com/http://www.microsoft.com/windowsazure/offers/
  • 7/30/2019 02-Article Introduction to Windows Azure

    11/19

    http://msdn.microsoft.com/rampup

    http://msdn.microsoft.com/rampup

    6. From the Deploy Windows Azure Project dialog, you can deploy the service package directly to

    Windows Azure. You can also choose to generate the service package and upload it yourself via the

    Management Portal.

    7. Click on the Credentials drop-down and select to add a new credential.

    8. From the Windows Azure Project Management Authentication dialog, click on the certificate drop

    down and select . Enter a friendly name that corresponds to the Windows Azure subscription

    you are authorizing Visual Studio to manage.

    9. Click the link to copy the full path of the certificate to the clipboard and use the Management Portal to

    upload that certificate to your account.

    10. While you are on the account page of the Management Portal, copy your subscription ID and paste it into

    the subscription ID text box in the Windows Azure Project Management Authentication dialog.

    11. Enter a name for these credentials. This name will show up when you are prompted to provide credentials.

    12. Select the hosted service slot and storage account you wish to use to deploy to Windows Azure.

    13. If you are using Visual Studio 2010 Ultimate with .NET 4 roles and wish to use IntelliTrace to debug issues

    in Windows Azure, you can enable IntelliTrace as part of the deployment.

    14. Hit OK to deploy to Windows Azure.

    15. Track the progress of the deployment through the Windows Azure Activity Log.

    Debugging Using IntelliTrace

    1. If you are using Visual Studio 2010 Ultimate with .NET 4 roles and enabled IntelliTrace as part of the

    deployment, you can make requests to get and view the IntelliTrace logs for an instance through theWindows Azure Compute Explorer in the Server Explorer.

    Formatted: Bullets and Numbering

    Formatted: Bullets and Numbering

    http://windows.azure.com/http://windows.azure.com/
  • 7/30/2019 02-Article Introduction to Windows Azure

    12/19

    http://msdn.microsoft.com/rampup

    http://msdn.microsoft.com/rampup

    2. Right-click on the instance for which you want to view IntelliTrace logs and select View IntelliTrace logs.

    3. The logs will be collected for that instance, uploaded to the Blob service, and then downloaded and

    opened in Visual Studio.

    4. With the log opened in Visual Studio, you can make use of the Visual Studio IntelliTrace debugging

    features to debug your hosted service.

    See Also

    Concepts

    Windows Azure Tools for Microsoft Visual Studio

    Formatted: Bullets and Numbering

    http://msdn.microsoft.com/en-us/library/ee405484.aspxhttp://msdn.microsoft.com/en-us/library/ee405484.aspx
  • 7/30/2019 02-Article Introduction to Windows Azure

    13/19

    http://msdn.microsoft.com/rampup

    http://msdn.microsoft.com/rampup

    Group Title

    Topic N: An Overview of Windows Azure

    http://msdn.microsoft.com/rampup

    http://msdn.microsoft.com/rampuphttp://msdn.microsoft.com/rampuphttp://msdn.microsoft.com/rampuphttp://msdn.microsoft.com/en-us/rampup/bb352986.aspx
  • 7/30/2019 02-Article Introduction to Windows Azure

    14/19

    http://msdn.microsoft.com/rampup

    http://msdn.microsoft.com/rampup

  • 7/30/2019 02-Article Introduction to Windows Azure

    15/19

    Page 1

    Contents

    INTRODUCTION ............................................................... .................................................................................... 2RESOURCES OFFERED BY WINDOWS AZURE ........................................................................ ................... 2ARCHITECTURE ........................................................................ ............................................................................ 3DEVELOPING FOR THE CLOUD ........................................................................ ............................................... 4ADDITIONAL RESOURCES............................................................................... ................................................. 5

  • 7/30/2019 02-Article Introduction to Windows Azure

    16/19

    Page 2

    Introduction

    For most shops, setting up an Internet-facing application requires them to set up a datacenter, hire people to monitor their

    applications, and acquire the hardware to host the application. Windows Azure was designed to dispense with almost all of

    that and provide a pay-as-you-go service that provides easy automatically-managed scalability and availability. The

    Windows Azure hosting platform nearly eliminates this need for hardware and human resource allocations, and instead

    enables developers to quickly and easily create applications that can run in the cloud by leveraging the skills they have

    already developed using the Microsoft .NET Framework and the Visual Studio development environment. Windows Azure

    also makes the job of developing, operating, and updating applications easier by providing reliable and expandable hosting

    services.

    When you host an application under Windows Azure, details like your applications deployment, keeping the servers up-to-

    date with the latest patches, ensuring the application is running, phasing out old hardware is handled by Microsoft so that

    you can focus on creating your application. Deployment and management of your service is automated by relying on a clear

    definition of your applications structure and configuration, with all of the actual work of ensuring that your application is

    deployed and kept running.

    Windows Azure was designed from the ground-up to provide an open, standards-based and interoperable environment. All

    communications with Windows Azure support standard internet protocols, including HTTP/HTTPS, REST, SOAP, and XML.

    Beyond this protocol interoperability, developers can implement their applications using a wide range of technologies

    including (but not limited to) the Microsoft.NET Framework, Java, and PHP.

    Resources Offered by Windows Azure

    Windows Azure has been designed from the ground-up to provide a platform for hosting Internet-facing applications in a

    reliable and scalable manner. Windows Azure also provides a set of supporting services that make developing scalable

    applications easier; services such as Azure Storage and the .NET Service Bus provide the infrastructure that would

    otherwise require a deep investment from the services developer.

    Compute Services

    The compute services are essentially the hosting environment for Windows Azure. It is in this environment that any

    executables that you deploy for your service reside. The Windows Azure platform is based upon the concept of having a

    model for your application; this model is defined by a set of application roles, and the Windows Azure infrastructure

    manages the lifetimes of the components that perform these roles. The Windows Azure currently defines two roles: that of a

    Web application (the Web Role) that services requests from external users and applications and that of a background

    worker that is constantly running in the background and has no externally-accessible endpoints (the Worker Role).

    Storage Services

    Azure Storage provides a robust and scalable way for your application to store virtually any data it needs without having to

    worry about availability or scalability. In its current form, Azure Storage provides three different types of storage: table

    storage for structured data, BLOB storage for storing opaque streams of data such as images or binary files, and queue

    storage for reliably passing messages between different application roles. For all three of these services, Azure Storage

    provides a Representational State Transfer (REST) front-end that may be accessed from either Windows Azure or from

    external applications.

  • 7/30/2019 02-Article Introduction to Windows Azure

    17/19

    Page 3

    .NET Service Bus

    One of the challenges of developing for a platform like Windows Azure is that of connectivity between external applications

    and the service that is being hosted. Due to the fact that the application is completely stateless and the fact that the

    internal hosting environment is fluid (i.e., the actual machine on which a component is running may change at any

    moment), it is not possible for the service and application to communicate through a direct channel. Another issue is that of

    delivering notifications to external applications; since at any given time connectivity to an Internet-based consumer of

    service notifications may be inaccessible, the service developer needs a way to queue up notifications so that the service

    can continue to process incoming requests while attempting to deliver the notification as well as a way to dispose of

    notifications that have timed out. The .NET Service bus provides this mechanism so that the service developer can focus

    on delivering their core functionality.

    Architecture

    Internally, the Windows Azure currently runs on Windows Server 2008 + NET 3.5 SP1. You may deploy any additional

    binaries your application will need provided that they do not require explicit installation on the machine. An example would

    be that you can include an unmanaged library that is used via P/Invoke to process text files, while requiring Microsoft Office

    so that you can use Word Interop would not be possible.

    In order to fulfill the design goal of high scalability and reliability, Windows Azures hosting fabric will deploy the virtual

    machines that host your application in such a manner that machines do not share the same power lines and network

    channels. In this way, complete service failures due to transient power and/or network outages can be avoided. In addition,

    the hosting fabric will also distribute machines across upgrade boundaries so that rolling upgrades will not be deployed to all

    machines that are performing the same role.

  • 7/30/2019 02-Article Introduction to Windows Azure

    18/19

    Page 4

    For the current version of the Azure Services Platform, the communications channels available for use to and from Azure

    services are HTTP(S) (inbound) and TCP (outbound), and inbound communications are limited to components that target

    the Web Role. The UDP communications protocol is not supported at the present, but functionality traditionally delivered

    through connectionless communications such as notifications may still be accomplished using the functionality supplied by

    the .NET Service bus.

    You will never know what server your code is executing on, so treat your development as if you were deploying to a Web

    Farm: do not rely on keep-alives for server/request affinity, do not store anything important using in-memory storage, and

    generally ensure your application is completely stateless. Leverage Azure Table Storage to persist things like carts, etc.

    REST-based for maximum interoperability

    Developing for the Cloud

    The Development Environment

    The Windows Azure SDK ships with a complete development environment that allows you to develop and debug your

    applications locally without needing to deploy the application to the cloud. In fact, you can fully develop and test most of

    your applications code before you even get an Azure account.

    Although you do not need to have Visual Studio to use the tools in the SDK, there is deep integration with the local cloud in

    a box that simplifies development, debugging and deployment through the Windows Azure Tools for Visual Studio. You can

    use either the full editions of Visual Studio as well as the free edition of Visual Studio Web Developer Express.

    Design Issues

    If you rely on Azure Storage, you do not have a schema as you do using a storage platform such as SQL Server or even SQL

    Azure; instead, the application must perform the job of confirming that the data being retrieved conforms to the expected

    structure, that relationships such as parent/child are consistent, and so on. I f your application requires a more structuredform of storage or requires consistency checks such as foreign keys, you should consider using the SQL Azure storage

    platform or a SQL Server instance hosted in your own environment.

    In order to accomplish the reliability and scalability features that Windows Azure delivers, it is necessary to be able to add

    new component instances on the fly as well as be able to redirect processing of incoming requests from one server to

    another at a moments notice. In order for your application to function properly in such a fluid environment, you should

    design your application to assume that each request is being processed in a stateless manner. As an example: where a

    Web-based application hosted in an Enterprises datacenter may have assumed that application state is being maintained

    between requests from the same client, in an environment such as Windows Azure that assumption is unlikely to be correct.

    Any time your application needs to maintain some form of state in a persistent manner, you should store this information in

    a durable store such as Azure Storage or SQL Azure and have mechanisms in place to retrieve this information if it is

    determined that it is not present on the machine processing a request that requires that state.

    Just as your application must assume that request processing is stateless and has no machine affinity, your application

    should also be designed to tolerate failure. The SQL Azure hosting fabric is designed to detect and handle hardware,

    software, and network failures and keep your application running, but this requires that your applications code include error

    checking and retry actions when a communications failure occurs. Just as your application should store state in durable

    stores to ensure that the information is accessible to any machine that handles the next request, you should write your code

    in such a manner that you rely on tables/queues for persisting the state of complex workflows and to tolerate duplication of

  • 7/30/2019 02-Article Introduction to Windows Azure

    19/19

    Page 5

    actions. In particular, your application should use storage patterns such as the upsert pattern (i.e., add if missing, update if

    present) and do not remove items from queues until the item being processed has committed all data.

    As there is no way to determine which machine in the hosting fabric a given component is running on, nor is there a way to

    attach a debugger to an instance, debugging of your application is only supported in the local development environment.

    This means that your application must include instrumentation to help you determine the cause of a failure once the service

    has been deployed. Developers should leverage the logging services provided by Windows Azure to ensure that they are

    able to provide themselves with the information they need to troubleshoot any runtime issues; good rules of thumb are to

    log important condition checks, log before and after cross-machine communications such as Web Service calls, and to

    include method arguments at the verbose logging level.

    Additional Resources

    Additional resources for learning about Windows Azure are listed below:

    Name Location

    Windows Azure Developers

    Portal

    http://www.microsoft.com/azure/windowsazurefordevelopers/default.aspx

    http://www.microsoft.com/azure/windowsazurefordevelopers/default.aspxhttp://www.microsoft.com/azure/windowsazurefordevelopers/default.aspxhttp://www.microsoft.com/azure/windowsazurefordevelopers/default.aspx