Logo
programming4us
programming4us
programming4us
programming4us
Home
programming4us
XP
programming4us
Windows Vista
programming4us
Windows 7
programming4us
Windows Azure
programming4us
Windows Server
programming4us
Windows Phone
 
Windows Azure

Performing storage account operations using REST (part 1) - Listing tables in the development storage account using the REST API

3/13/2011 4:49:49 PM
- Free product key for windows 10
- Free Product Key for Microsoft office 365
- Malwarebytes Premium 3.7.1 Serial Keys (LifeTime) 2019
For now, we’ll concentrate purely on the operations that you can perform against a storage account using the REST API. Although we’ve already looked at these operations using the StorageClient library, it’s still useful to look at the REST API. Ultimately, the StorageClient library is just a wrapper library for the calls we’re about to look at. Over the next few sections, we’ll look at the following operations:
  • Listing tables

  • Deleting tables

  • Creating tables

The URI of the Table service endpoint uses the following structure:

http://<storageaccount>.table.core.windows.net/

If your storage account was named silverlightukstorage, your URI would be the following:

http://silverlightukstorage.table.core.windows.net/

For the development storage Table service, you’d use the following URI:

http://127.0.0.1:10002/devstoreaccount1/

Now that you know what the URIs will look like, let’s try using them.

1. Listing tables in the development storage account using the REST API

We looked at a small console application that listed all the containers in a BLOB storage account using the REST API. In this section, you’ll create a similar console application that will list all the tables in a development storage account. Figure 1 shows the output of this console application.

Figure 1. A console application that returns a list of tables in a storage account—that’s a lot of XML just to return a list containing the name of one table.


If you look at the output in figure 1 you can see that the Products table is returned in the list of storage accounts.

Does that funny-looking XML follow some sort of standard?

As you may have already gathered, normal people don’t create APIs that output XML like what you see in figure 1. You need a standard to generate that level of verboseness and complexity.

The standard that the Table service uses to expose its data is known as AtomPub. We’ll discuss it in more detail later.

If you’re interested in being able to identify AtomPub documents in the wild, you can always look at the XML namespace. As you can see in figure 1, it’s referencing the Atom namespace:

xmlns=http://www.w3.org/2005/Atom


If you wanted to list all the tables in a storage account using the StorageClient library, you could do the following:

var storageAccount =
CloudStorageAccount.Parse(
ConfigurationManager.AppSettings["DataConnectionString"]);

CloudTableClient tableClient =
storageAccount.CreateCloudTableClient();

tableClient.ListTables();

Let’s now take a look at how this could be done using the REST API directly. You might not usually do this directly with REST, but we want you to appreciate what’s really happening behind the scenes.

In order to get a list of all tables that exist in the storage account, all you need to do is write some code that will perform a GET request against the following URIs:

http://127.0.0.1:10002/devstoreaccount1/Tables (for dev storage)
http://<storageaccount>.table.core.windows.net/Tables (for live)

To create the application that generated the output shown in figure 1, you’ll need to create a new console application in Visual Studio. To keep the example simple, we’ll reuse the StorageClient library’s credential-signing method.

The following listing contains the code for the console application.

Listing 1. Listing the tables in a storage account

The code displayed in listing 1 will make a GET request to the development Table service asking for a list of all the tables in the storage account (http://127.0.0.1:10002/devstoreaccount1/Tables).

At , you generate the HTTP request by calling the CreateHttpRequest method. This method creates the HttpRequest for the given URI (http://127.0.0.1:10002/devstoreaccount1/Tables) and HTTP verb (GET) and returns the request to the calling method.

Sign Request Lite

You’ve probably noticed that listing 12.1 makes use of the storage account credentials from the StorageClient library , even though it’s using the REST API. The major reason for this is that signing the HTTP request manually is hard and horrible. Rather than writing that nasty code, it’s easier to use the StorageClient library method.


Finally, with the request generated and signed, you can make the request to the development service . The Table service will return an XML response listing all of the tables in your account, which is written to the console window, as you saw in figure 12.1.

Switching to the Live Service

In listing 1 you made a request to the development storage Table service. If you wanted to change the application to query a live service (such as a silverlightukstorage storage account) you’d need to change the URI at to http://silverlightukstorage.table.core.windows.net/Tables.

It’s worth pointing out that although the URI in listing 1 is hardcoded, you could extract it from the storageAccount object:

storageAccount.TableEndpoint.AbsoluteUri.ToString();

This is just the base URI; you’ll still need to append /tables to access the Table service.

Other -----------------
- Doing CRUDy stuff with the Table service (part 3) - Deleting entities & Updating entities
- Doing CRUDy stuff with the Table service (part 2) - Adding entities & Listing entities
- Doing CRUDy stuff with the Table service (part 1) - Creating a context class
- Developing with the Table service
- Partitioning data across lots of servers : Partitioning the storage account & Partitioning tables
- Modifying an entity to work with the Table service
- How we’d normally represent entities outside of Azure
- A brief overview of the Table service
- BLOBs : Setting shared access permissions
- Enterprise Service Bus with BizTalk Server and Windows Azure : Distributed and Scalable ESB Architecture
 
 
Top 10
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Finding containers and lists in Visio (part 2) - Wireframes,Legends
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Finding containers and lists in Visio (part 1) - Swimlanes
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Formatting and sizing lists
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Adding shapes to lists
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Sizing containers
- Microsoft Access 2010 : Control Properties and Why to Use Them (part 3) - The Other Properties of a Control
- Microsoft Access 2010 : Control Properties and Why to Use Them (part 2) - The Data Properties of a Control
- Microsoft Access 2010 : Control Properties and Why to Use Them (part 1) - The Format Properties of a Control
- Microsoft Access 2010 : Form Properties and Why Should You Use Them - Working with the Properties Window
- Microsoft Visio 2013 : Using the Organization Chart Wizard with new data
 
programming4us
Windows Vista
programming4us
Windows 7
programming4us
Windows Azure
programming4us
Windows Server