2016-04-01 47 views
0

SAS Token Error IN Xamarin Studio IMAGE403時,請訪問Windows Azure存儲表在Xamarin

我一直在嘗試使用xamarin工作室VS2k15對我使用Android應用development.the數據庫驗證錯誤是Azure存儲表。

因此,爲了在xamarin中使用azure存儲表,您需要SAS(共享訪問簽名)而不是Access密鑰。

我爲表存儲生成了SAS令牌,但是此異常(如圖所示)被拋出而不是插入數據。

enter image description here

HTTP 403表示連接工作和接受請求但它是在做的工作失敗。

所以請幫助我。 P.Sas令牌已正確生成(由於安全原因無法共享)。

我的主要活動的.cs

using Microsoft.WindowsAzure.Storage; 

使用Microsoft.WindowsAzure.Storage.Table;

命名空間APP6 { [活性(標籤= 「Docapp」,MainLauncher =真,圖標= 「@繪製/圖標」)] 公共類MainActivity:活動 {

protected override void OnCreate(Bundle bundle) 
    { 
     base.OnCreate(bundle); 

     // Set our view from the "main" layout resource 
     SetContentView(Resource.Layout.Main); 

     // Get our button from the layout resource, 
     // and attach an event to it 
     Button button = FindViewById<Button>(Resource.Id.MyButton); 

     button.Click += async delegate 
     { 
      appfix temp = new appfix("public", "1001", "2123212", "djnsjd", DateTime.Today, DateTime.UtcNow, "snjdn", 1233, "JDdjvn", "dsjd", 1212, 0); 
      string d = await insert(temp); 
      TextView tv = FindViewById<TextView>(Resource.Id.textView1); 
      tv.Text = d; 
     }; 


    } 




    private async Task<string> insert(appfix temp) 
    { 
     string sas = "https://supapp.table.core.windows.net/request?sv=2015-04-05&tn=request&sig=FlXvYraZKJIz6YQaRpzVBPORPLsyRKMZHQiAVBPkYP0%3D&spr=http%2Chttp&se=2016-04-01T15%3A44%3A49Z&sp=raud"; 

     string dec; 
     try 
     { 
      // CloudStorageAccount storageAccount = CloudStorageAccount.Parse(key); 

      // CloudTableClient tableClient = storageAccount.CreateCloudTableClient(); 


      CloudTable table = new CloudTable(new Uri(sas)); 
       //tableClient.GetTableReference(tableName); 

      TableOperation insertEntity = TableOperation.InsertOrReplace(temp); 

      await table.ExecuteAsync(insertEntity); 

      dec = "DONE"; 
     } 

     catch(Exception e) 
     { 
      dec = e.ToString(); 
     } 

     return dec; 
    } 

我的AppFix類

using Microsoft.WindowsAzure.Storage; 

using System.Threading.Tasks;

命名空間APP6 { 公共類的AppFix:TableEntity { 公共字符串app_no {獲得;組; } public string app_with {get;組; } public DateTime app_date {get;組; } public DateTime app_time {get;組; } public string patient_name {get;組; } public int ser_no {get;組; } public string patient_rank {get;組; } public string patient_aliment {get;組; } public int room_no {get;組; } public int app_status {get;組; }

public appfix() 
    { 

    } 
    public appfix(string partionkey,string rowkey,string App_no, string App_with, DateTime App_date, DateTime App_time, string Patient_name, int Ser_no, string Patient_rank, string Patient_aliment, int Room_no, int App_status) 
    { 
     this.PartitionKey = partionkey; 
     this.RowKey = rowkey; 
     this.app_no = App_no; 
     this.app_with = App_with; 
     this.app_date = App_date; 
     this.app_time = App_time; 
     this.patient_name = Patient_name; 
     this.ser_no = Ser_no; 
     this.patient_rank = Patient_rank; 
     this.patient_aliment = Patient_aliment; 
     this.room_no = Room_no; 
     this.app_status = App_status; 
    } 


} 

}

我SAS令牌

https://supapp.table.core.windows.net/request?sv=2015-04-05&tn=request&sig=FlXvYraZKJIz6YQaRpzVBPORPLsyRKMZHQiAVBPkYP0%3D&spr=http%2Chttp&se=2016-04-01T15%3A44%3A49Z&sp=raud 
+0

您是如何爲表格生成SAS令牌的?您可以共享SAS令牌...只需用其他值替換帳戶名稱和表名。 –

+0

我從azure powershell生成了SAS TOKEN。 $ context = New-AzureStorageContext -StorageAccountName「xyz」-StorageAccountKey「XYZ」 Get-AzureStorageTable請求-Context $ context $ now = Get-Date New-AzureStorageTableSASToken -Name請求-Permission radu -ExpiryTime $ now.AddDays(1.0 )-Context $ context -FullUri這是我如何生成我的SAS令牌。 – Sam

+0

謝謝你分享的細節。我嘗試使用上面共享的PowerShell代碼爲表創建SAS令牌,並使用該代碼成功執行操作。我希望您檢查兩件事:1)用於創建SAS令牌的帳戶密鑰和2)設備上的時間。這兩個都可能導致403錯誤。 –

回答

0

Solved Issue IMG

的問題是解決了,感謝拉夫Mantri。

首先,我將Azure Power Shell從1.2.3更新到1.3.0,並將WindowsAzure Storage從4.4.1更新到5.0.3預覽。

爲什麼我使用5.0.3,因爲Monoandroid 6.0支持5.0.3。

SAS令牌具有來自1.2.3 windows azure電源外殼的SPR參數,但在1.3.0中不添加spr參數。

因此錯誤得到解決。