2010-12-11 62 views
0

我正在开发Windows Phone 7应用程序。其中的一部分是在笔记本电脑上创建一个用于在Windows Azure云上创建表格的webrole,这已经完成了。我正在Windows Phone 7上开发一个Silverlight应用程序,它需要访问云来查询表格并更新它们。我在互联网上的很多地方都发现,这可以通过对Windows TAble存储进行RESTful调用来完成。但是我找不到任何示例代码。Silverlight RESTful Azure Table Access

任何人都可以发布一些示例代码如何RESTful调用Windows表存储完成,以便我可以从客户端(Silverlight应用程序 - Windows Phone 7)查询和更新表。任何链接和引用也是受欢迎的。

+0

什么是你的应用程序的安全模型?您的应用的每个用户是否拥有存储帐户? (您不应将_your_存储钥匙交给客户端......任何使用存储钥匙的人都可以删除所有数据,将其替换为私人DVD收藏夹等) – smarx 2010-12-12 09:13:47

+0

否..每个用户都不拥有存储帐户..什么是安全模型? – Aditya 2010-12-12 19:04:12

+0

看看这个博客。似乎是全面的http://convective.wordpress.com/2010/08/18/examples-of-the-windows-azure-storage-services-rest-api/ – Chandermani 2010-12-13 12:34:52

回答

1

这是关于基于REST调用到Windows表存储

清单表一些示例代码:

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

删除表:

http://<storageaccount>.table.core.windows.net/Tables('TableName') 

为了创建你有一个新的表创建POST请求到下一个Uri:

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

这可能是您的要求的身体:

<?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> 

如果你需要插入一个新的实体,您应该使用下一个开放的:

POST http://<storageaccountname>.table.core.windows.net/<TableName> 

和请求体为以下的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> 

删除实体

http://<storageaccountname>.table.core.windows.net/<TableName>(PartitionKey="Definitions", 
RowKey="Things") 

使用REST API来更新或合并数据实际上是DELETE和插入REST API的组合。 的URI来更新或合并本地实体回表存储是相同的URI删除操作

http://<storageaccountname>.table.core.windows.net/<TableName>(PartitionKey="Definitions", 
RowKey="Things")