English 中文(简体)
Accessing Azure Table entities
原标题:

So I have this app which needs 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 wrapper?
2) I m guessing no, so I tried with the REST API and I always get the 403 Forbidden 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();
最佳回答

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

问题回答

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

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 showed my the way.





相关问题
Allow RESTful DELETE method in asp.net mvc?

im currently setting up asp.net to accept DELETE http verb in the application. However, when i send "DELETE /posts/delete/1" i always get a 405 Method not allow error. I tried to take a look at ...

Most appropriate API for URL shortening service

I ve just finished an online service for shortening URLs (in php5 with Zend Framework); you can enter an URL and you get an short URL (like tinyurl and such sites). I m thinking about the API for ...

Use HTTPClient or HttpUrlConnection? [closed]

We re implementing a REST client on JRE 1.4. Seems two good options for a client REST framework are HttpClient and HttpUrlConnection. Is there a reason to use HttpClient over the JRE s ...

Why can t I find the truststore for an SSL handshake?

I m using the Spring RESTTemplate on the client side to make calls to a REST endpoint. The client in this case is a Spring app and Tomcat is the servlet container. I m running into issues making a ...

Which Http redirects status code to use?

friendfeed.com uses 302. bit.ly uses 301. I had decided to use 303. Do they behave differently in terms of support by browsers ?

Three Step Buyonline The RESTful way

We are re-developing our buyonline functionality and we are doing it the RESTful way. The process is a three step one and the customer is asked to enter data at each step. Let s say the three URL s ...

热门标签