January 25, 2021
Hot Topics:

Building in the Cloud with Azure Storage and the Azure SDK

  • By Matt Goebel
  • Send Email »
  • More Articles »

The endpoint values shown are for the development environment. To verify your development Azure storage endpoints debug the application and open the Development Storage management window found in the system tray. If this is your first time starting the development storage the Table service will be stopped because the development storage tables have not yet been created. You will create these as part of a later step.

Figure 1.1 - New Cloud Service
Click here for larger image

Figure 1.3 First Run of Development Storage

In Default.aspx add two text boxes and a button for collecting the two values to add with a label to display a retrieval key. Then add an additional textbox and button to retrieve the calculated value and a label to display the calculated value. For each button create the click event handler. Figure 1.4 below shows the form with all controls plus layout and some labels.

Figure 1.1 - New Cloud Service
Click here for larger image

Figure 1.4 ASP.NET Form w/Controls

At this point in the walkthrough you have completed the initial setup of the application, configured it with Azure Storage account information and laid out the user interface. The following steps will add the wiring to consume Azure Storage and interact across cloud service roles.

Windows Azure Storage

There are three types of storage available in Windows Azure Storage; Tables, Blobs and Queues. Blob storage is meant for storing large chunks of unstructured data. Queue storage is intended to be used as temporary messaging between Web roles and Worker roles. Finally, Table storage is meant for storing structured data in a scalable method. Below is a table for quick reference.

Windows Azure Storage Types

Important: Table storage is NOT the same thing as Azure SQL or for that matter has anything at all to do with a relational database model. Table storage is not relational.

Azure Storage is accessed via a REST interface and therefore is accessible by anything that can make HTTP request. It also means that Table storage is accessible using ADO.NET Data Services. Lucky for us Microsoft has already built a managed code wrapper for interfacing with Azure Storage as part of the Azure SDK. As of the July CTP the project is called StorageClient and can be found (full source) in "C:\Program Files\Windows Azure SDK\v1.0\Samples\StorageClient" after installing the Azure SDK. You can either directly add this project to your cloud service solution or compile the assembly and reference it in your solution. The StorageClient interface will be used throughout this example to consume Table and Queue storage.

Using Windows Azure Table Storage

Table storage in development varies slightly from what is found in the Windows Azure Storage services. One example of this difference is that development Table storage requires that the tables have a fixed schema. Table storage in the full Azure Storage service does not require table configuration and supports adding varying numbers and types of properties to numerous entities within the same table. A complete list of development and production differences can be found at http://msdn.microsoft.com/en- us/library/dd320275.aspx.

To create the table schema and data service context for accessing the table's data create two separate classes. Call the first class "Calculation.cs" and the second "CalculationDataServiceContext.cs". In the project that these two classes are created, add a new Reference to System.Data.Services.Client. Then add the following to each respective class.

(In line comments provide additional details)

  public class Calculation : Microsoft.Samples.ServiceHosting.StorageClient.TableStorageEntity
          // Inheriting from TableStroageEntiry predefines the 3 necessary
          // properties for storing any entity in Table storage; PartitionKey, 
          // RowKey and TimeStamp
          public Calculation()
              // Hardcoded for this example but can be anything; best practice
              // is to assign the PartitionKey based on a value that groups
              // your data to optimize search performance.
              PartitionKey = "TEST";
              // Unique identifier with each partition
              RowKey = DateTime.Now.Ticks.ToString();
          public int ValueOne { get; set; }
          public int ValueTwo { get; set; }
          public int CalcValue { get; set; }
  public class CalculationDataServiceContext : TableStorageDataServiceContext
          public CalculationDataServiceContext(StorageAccountInfo accountInfo)
              : base(accountInfo)
          { }
          // Properties that return IQueryable<T> are used by VS to create a
          // table in development storage named after the property.  The 
          // schema is defined by the public properites in the model class.
          public IQueryable<CALCULATION> Calculations
                  return this.CreateQuery<CALCULATION>("Calculations");
          // Method to take two input values, input them into the table storage 
          // and returns the RowKey so the value can be later retrieved.
          public string AddCalculation(int valueOne, int valueTwo)
              Calculation calc = new Calculation();
              calc.ValueOne = valueOne;
              calc.ValueTwo = valueTwo;
              this.AddObject("Calculations", calc);
              return calc.RowKey;

After successfully creating the two classes, the next step is to create the test storage tables via Visual Studio. In the Solution Explorer, right-click on the MyCloudService project and select "Create Test Storage Tables". Visual Studio will display a message when it is complete. You will now be able to debug the application, open the Development Storage management window and see the Table service running.

Page 2 of 4

This article was originally published on November 12, 2009

Enterprise Development Update

Don't miss an article. Subscribe to our newsletter below.

Thanks for your registration, follow us on our social networks to keep up-to-date