2. Deleting tables using the REST API
To delete a table using the StorageClient library, you need to call the DeleteTable method of your CloudTableClient object, passing in the name of the table that you wish to delete. The following code would delete the Products table:
var storageAccount =
CloudStorageAccount.Parse(
ConfigurationManager.AppSettings["DataConnectionString"]);
CloudTableClient tableClient =
storageAccount.CreateCloudTableClient();
tableClient.DeleteTable("Products");
If you wanted to delete the same table using the REST API directly, you could perform an HTTP DELETE (rather than a GET) request using the following URI:
http://silverlightukstorage.table.core.windows.net/Tables('Products')
To modify listing 1 to delete the Products table, you could replace the code at with the following:
HttpWebRequest hwr =
CreateHttpRequest(new Uri(@"http://silverlightukstorage.table.core.windows.net/Tables('Products')"), "DELETE", new TimeSpan(0, 0, 30));
As you can see, this code replaces the original GET request with a DELETE, and the URI has been modified. Because you no longer need to process an XML response, you’d also need to change the code at as follows:
Finally,
because the code now uses the live Table service rather than the
development storage version, you’d also need to set the correct
credentials.
You’ve now had a chance to
interact with the Table service both via the StorageClient library and
by using the REST API directly, so let’s look at some of the
technologies used to implement the Table service REST API.
3. WCF Data Services and AtomPub
WCF Data Services (formerly
known as Astoria) is a data-access framework that allows you to create
and consume data via REST-based APIs from your existing data sources
(such as SQL Server databases) using HTTP.
Rather than creating a whole
new protocol for the Table service API, the Windows Azure team built the
REST-based APIs using WCF Data Services. Although not all aspects of
the Data Services framework have been implemented, the Table service
supports a large subset of the framework.
One of the major advantages of
WCF Data Services is that if you’re already familiar with the
framework, getting started with the Windows Azure Table service is
pretty easy. Even if you haven’t used the WCF Data Services previously,
any knowledge gained from developing against Windows Azure storage will
help you with future development that may use the framework.
WCF Data Services Client Libraries
WCF Data Services provides a
set of standard client libraries that abstract away the complexities of
the underlying REST APIs and allow you to interact with services in a
standard fashion regardless of the underlying service. Whether you’re
using WCF Data Services with the Windows Azure Table service or SQL
Server, your client-side code will be pretty much the same.
AtomPub
The Windows Azure Table
service uses the WCF Data Services implementation of the Atom Publishing
Protocol (AtomPub) to interact with the Table service. AtomPub is an
HTTP-based REST-like protocol that allows you to publish and edit
resources. AtomPub is often used by blog services and content management
systems to allow the editing of resources (articles and blog postings)
by third-party clients. Windows Live Writer is a well-known example of a
blog client that uses AtomPub to publish articles to various blog
platforms (Blogspot, WordPress, Windows Live Spaces, and the like). In
the case of Windows Azure storage accounts, tables and entities are all
considered as resources.
Although WCF Data
Services can support other serialization formats (such as JSON) the
Table service implementation of WCF Data Services only supports AtomPub.
If you’re interested in reading more about the AtomPub protocol (RFC 5023) you can read the full specification here: http://bitworking.org/projects/atom/rfc5023.html.
Now that you have a basic
awareness of AtomPub, we can look at how the AtomPub protocol and the
Atom document format are used to create a table using the Table service
REST API.