2010-12-11 56 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")