views:

209

answers:

3

So I have this app which need to query entities from the Azure Tables storage from tables I don't know the schema of.

1) Is there a way I can do that with the Storageclient wraper?
2) I'm guessing no, so I tryied with the REST API and I always get the 403 Forbiden when I query for the entities.

This is my code.

HttpWebRequest request = (HttpWebRequest)WebRequest.Create(string.Format("http://{0}.table.core.windows.net/Tables('{1}')", account,query));
request.UserAgent = " Microsoft ADO.NET Data Services";
request.KeepAlive = true;
request.Method = "GET";
request.Headers.Add("x-ms-version", "2009-09-19");
request.Headers.Add("x-ms-date", string.Format("{0} GMT", DateTime.UtcNow.ToString ("ddd, dd MMM yyyy HH:mm:ss")));
request.Headers.Add("Authorization", string.Format("SharedKey {0}:{1}", account, key));
request.Accept = "application/atom+xml,application/xml";
request.Headers.Add("Accept-Charset", "UTF-8");
request.Headers.Add("DataServiceVersion", "1.0;NetFx");
request.Headers.Add("MaxDataServiceVersion", "1.0;NetFx");

HttpWebResponse response = (HttpWebResponse)request.GetResponse();

Thanks in advance.

+1  A: 

Yes, you can do it. There is a good entry on how to at: http://social.msdn.microsoft.com/Forums/en-US/windowsazure/thread/481afa1b-03a9-42d9-ae79-9d5dc33b9297/

It gives a good code example so I won't elaborate on it. This code is pretty much what I use in my AzureTableQuery project to find out the properties of an entity. If you look at the code, check out the GenericTableContext.cs and GenericEntity.cs classes

Jason Haley
thanks @Jason, great solution!
sebastian
A: 

My initial problem was due to the fact that my Autorization header was not right.
I was just adding the key and there's actually a few thing you need to do with the key, sign a string and add that to the Autorization header.
More info here.

So why did I mark @Jason's answer as valid? Because my assumptions were wrong. There is a way to query entities in your Azure Tables even if you don't know the schema of your tables. And Jason's post howed my the way.

sebastian
A: 

Windows Azure Tables are queryable via OData (odata.org) protocol. The easiest way is to have the PartitionKey and the RowKey of the entity who want to get/update/merge/delete.

All REST examples are there (for tables query and entities query): http://msdn.microsoft.com/en-us/library/dd179423.aspx

Philippe