Reputation: 1
I am developing a Windows Phone 7 application. One part of it is to create a webrole on the laptop for creating tables on the Windows Azure cloud which I have already finished. I am developing a Silverlight application on Windows Phone 7 which needs to access the cloud for querying the tables and updating them. I have found at lot of places in the internet that this can be done by making RESTful calls to the Windows TAble Storage. But nowhere I could find any sample code.
Can anybody post some sample code how RESTful calls to Windows Table Storage is done, so that I can query and update the tables from the Client(Silverlight Application - Windows Phone 7). Any links and references are also welcome.
Upvotes: 0
Views: 326
Reputation: 17
this is some sample code about RESTful calls to Windows Table Storage
Listing tables:
http://<storageaccount>.table.core.windows.net/Tables
Deleting tables:
http://<storageaccount>.table.core.windows.net/Tables('TableName')
In order to create a new table you have to create a POST request to the next Uri:
POST http://<storageaccount>.table.core.windows.net/Tables
And this could be the body for your request:
<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<entry xmlns:d="http://schemas.microsoft.com/ado/2007/08/dataservices"
xmlns:m="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata"
xmlns="http://www.w3.org/2005/Atom">
<title />
<updated>2010-11-18T11:48:34.9840639-07:00</updated>
<author>
<name/>
</author>
<id/>
<content type="application/xml">
<m:properties>
<d:TableName>ProductTable</d:TableName>
</m:properties>
</content>
</entry>
If you need INSERT a new entity, you should use the next Uri:
POST http://<storageaccountname>.table.core.windows.net/<TableName>
And the request body as the following Atom XML:
<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<entry xmlns:d="http://schemas.microsoft.com/ado/2007/08/dataservices"
xmlns:m="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata"
xmlns="http://www.w3.org/2005/Atom">
<title />
<updated>2010-12-13T13:26:48.8875037Z</updated>
<author>
<name />
</author>
<id />
<content type="application/xml">
<m:properties>
<d:Description>My descripcion</d:Description>
<d:Name>Entity Name</d:Name>
<d:PartitionKey>Definitions</d:PartitionKey>
<d:RowKey>Things</d:RowKey>
<d:Timestamp m:type="Edm.DateTime">0001-01-01T00:00:00</d:Timestamp>
</m:properties>
</content>
</entry>
Deleting entities
http://<storageaccountname>.table.core.windows.net/<TableName>(PartitionKey="Definitions",
RowKey="Things")
Using the REST API to update or merge data is really a combination of the DELETE and the insert REST API's. The URI to update or merge the local entity back to the table storage is the same URI as the delete operation
http://<storageaccountname>.table.core.windows.net/<TableName>(PartitionKey="Definitions",
RowKey="Things")
Upvotes: 1