2

如何在Xamarin.Android上使用Microsoft Azure存儲模擬器? 我已經下載了Microsoft Azure存儲模擬器和Microsoft Azure存儲資源管理器。我試圖在Microsoft網站上關注教程,但仍然遇到了身份驗證問題。當我在免費試用期間使用real時,一切正常。如何在Xamarin中使用Microsoft Azure存儲模擬器?

我知道我必須使用SAS密鑰。但是,當我在存儲資源管理器中創建表存儲並在那裏生成SAS時,它仍然是錯誤的。也許有人已經這樣做了,可以粘貼他的代碼或步驟來重現與存儲模擬器的連接。

const string connectionString = "SharedAccessSignature=sv=2015-04-05&sr=c&sig=91HcGtCMxWM6%2B13mRDH1kej5Wq1a8gRk4WCFd6CeLuk%3D&se=2016-08-01T12%3A16%3A55Z&sp=rwdl;TableEndpoint=http://127.0.0.1:10002/devstoreaccount1"; 

CloudStorageAccount storageAccount = CloudStorageAccount.Parse(connectionString); 
CloudTableClient tableClient = storageAccount.CreateCloudTableClient(); 
CloudTable table = tableClient.GetTableReference("Test"); 
bool exists = await table.ExistsAsync(); 
if (exists) 
    System.Console.WriteLine("Exists"); 
else 
    System.Console.WriteLine("Doesnt exist"); 

錯誤詳細信息:

<RequestResult> 
    <HTTPStatusCode>0</HTTPStatusCode> 
    <HttpStatusMessage /> 
    <TargetLocation>Primary</TargetLocation> 
    <ServiceRequestID /> 
    <ContentMd5 /> 
    <Etag /> 
    <RequestDate /> 
    <StartTime>Sun, 31 Jul 2016 13:43:44 GMT</StartTime> 
    <EndTime>Sun, 31 Jul 2016 13:43:44 GMT</EndTime> 
    <Error></Error> 
    <ExceptionInfo> 
    <Type /> 
    <HResult>-2146233088</HResult> 
    <Message>Error: ConnectFailure (Connection refused)</Message> 
    <Source /> 
    <StackTrace /> 
    <InnerExceptionInfo> 
     <ExceptionInfo> 
     <Type /> 
     <HResult>-2146233079</HResult> 
     <Message>Error: ConnectFailure (Connection refused)</Message> 
     <Source>mscorlib</Source> 
     <StackTrace> at System.Net.HttpWebRequest.EndGetResponse (IAsyncResult asyncResult) [0x0005e] in /Users/builder/data/lanes/2923/52635947/source/mono/mcs/class/System/System.Net/HttpWebRequest.cs:1005 
    at System.Threading.Tasks.TaskFactory`1[TResult].FromAsyncCoreLogic (IAsyncResult iar, System.Func`2 endFunction, System.Action`1 endAction, System.Threading.Tasks.Task`1 promise, Boolean requiresSynchronization) [0x00014] in /Users/builder/data/lanes/2923/52635947/source/mono/external/referencesource/mscorlib/system/threading/Tasks/FutureFactory.cs:550 
--- End of stack trace from previous location where exception was thrown --- 
    at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() [0x0000c] in /Users/builder/data/lanes/2923/52635947/source/mono/external/referencesource/mscorlib/system/runtime/exceptionservices/exceptionservicescommon.cs:143 
    at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess (System.Threading.Tasks.Task task) [0x00047] in /Users/builder/data/lanes/2923/52635947/source/mono/external/referencesource/mscorlib/system/runtime/compilerservices/TaskAwaiter.cs:187 
    at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification (System.Threading.Tasks.Task task) [0x0002e] in /Users/builder/data/lanes/2923/52635947/source/mono/external/referencesource/mscorlib/system/runtime/compilerservices/TaskAwaiter.cs:156 
    at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd (System.Threading.Tasks.Task task) [0x0000b] in /Users/builder/data/lanes/2923/52635947/source/mono/external/referencesource/mscorlib/system/runtime/compilerservices/TaskAwaiter.cs:128 
    at System.Runtime.CompilerServices.ConfiguredTaskAwaitable`1+ConfiguredTaskAwaiter[TResult].GetResult() [0x00000] in /Users/builder/data/lanes/2923/52635947/source/mono/external/referencesource/mscorlib/system/runtime/compilerservices/TaskAwaiter.cs:535 
    at System.Net.Http.HttpClientHandler+&lt;SendAsync&gt;c__async0.MoveNext() [0x003d6] in /Users/builder/data/lanes/2923/52635947/source/mono/mcs/class/System.Net.Http/System.Net.Http/HttpClientHandler.cs:372 
--- End of stack trace from previous location where exception was thrown --- 
    at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() [0x0000c] in /Users/builder/data/lanes/2923/52635947/source/mono/external/referencesource/mscorlib/system/runtime/exceptionservices/exceptionservicescommon.cs:143 
    at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess (System.Threading.Tasks.Task task) [0x00047] in /Users/builder/data/lanes/2923/52635947/source/mono/external/referencesource/mscorlib/system/runtime/compilerservices/TaskAwaiter.cs:187 
    at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification (System.Threading.Tasks.Task task) [0x0002e] in /Users/builder/data/lanes/2923/52635947/source/mono/external/referencesource/mscorlib/system/runtime/compilerservices/TaskAwaiter.cs:156 
    at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd (System.Threading.Tasks.Task task) [0x0000b] in /Users/builder/data/lanes/2923/52635947/source/mono/external/referencesource/mscorlib/system/runtime/compilerservices/TaskAwaiter.cs:128 
    at System.Runtime.CompilerServices.ConfiguredTaskAwaitable`1+ConfiguredTaskAwaiter[TResult].GetResult() [0x00000] in /Users/builder/data/lanes/2923/52635947/source/mono/external/referencesource/mscorlib/system/runtime/compilerservices/TaskAwaiter.cs:535 
    at System.Net.Http.HttpClient+&lt;SendAsyncWorker&gt;c__async0.MoveNext() [0x000a9] in /Users/builder/data/lanes/2923/52635947/source/mono/mcs/class/System.Net.Http/System.Net.Http/HttpClient.cs:276 
--- End of stack trace from previous location where exception was thrown --- 
    at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() [0x0000c] in /Users/builder/data/lanes/2923/52635947/source/mono/external/referencesource/mscorlib/system/runtime/exceptionservices/exceptionservicescommon.cs:143 
    at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess (System.Threading.Tasks.Task task) [0x00047] in /Users/builder/data/lanes/2923/52635947/source/mono/external/referencesource/mscorlib/system/runtime/compilerservices/TaskAwaiter.cs:187 
    at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification (System.Threading.Tasks.Task task) [0x0002e] in /Users/builder/data/lanes/2923/52635947/source/mono/external/referencesource/mscorlib/system/runtime/compilerservices/TaskAwaiter.cs:156 
    at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd (System.Threading.Tasks.Task task) [0x0000b] in /Users/builder/data/lanes/2923/52635947/source/mono/external/referencesource/mscorlib/system/runtime/compilerservices/TaskAwaiter.cs:128 
    at System.Runtime.CompilerServices.TaskAwaiter`1[TResult].GetResult() [0x00000] in /Users/builder/data/lanes/2923/52635947/source/mono/external/referencesource/mscorlib/system/runtime/compilerservices/TaskAwaiter.cs:357 
    at Microsoft.WindowsAzure.Storage.Core.Executor.Executor+&lt;ExecuteAsyncInternal&gt;d__6`1[T].MoveNext() [0x003cf] in c:\Program Files (x86)\Jenkins\workspace\release_dotnet_master\Lib\WindowsRuntime\Core\Executor\Executor.cs:128 </StackTrace> 
     <InnerExceptionInfo> 
      <ExceptionInfo> 
      <Type /> 
      <HResult>-2147467259</HResult> 
      <Message>Connection refused</Message> 
      <Source>System</Source> 
      <StackTrace> at System.Net.Sockets.Socket.Connect (System.Net.EndPoint remoteEP) [0x000cb] in /Users/builder/data/lanes/2923/52635947/source/mono/mcs/class/System/System.Net.Sockets/Socket.cs:1313 
    at System.Net.WebConnection.Connect (System.Net.HttpWebRequest request) [0x0019b] in /Users/builder/data/lanes/2923/52635947/source/mono/mcs/class/System/System.Net/WebConnection.cs:195 </StackTrace> 
      </ExceptionInfo> 
     </InnerExceptionInfo> 
     </ExceptionInfo> 
    </InnerExceptionInfo> 
    </ExceptionInfo> 
</RequestResult> 

謝謝您的時間。

+0

你能解釋一下你的意思嗎?但是當我在存儲資源管理器中創建表存儲,然後生成SAS它仍然是錯誤的? SAS有什麼問題? –

+0

當我嘗試連接到使用該SAS的存儲時,我得到關於連接失敗的例外 – wasilewitz

+0

我明白了。您能否請您分享您的SAS令牌以及使用該SAS令牌連接到存儲的代碼? –

回答

0

我相信你得到這個錯誤是因爲你在模擬器中運行這段代碼。由於模擬器的IP地址爲127.0.0.1,請求實際上並不是實際觸及存儲模擬器,而只是您的設備模擬器。這就是爲什麼你得到這個連接拒絕錯誤。請參閱此主題了解更多詳情:https://forums.xamarin.com/discussion/1199/how-to-make-our-remote-host-127-0-0-1-reachable-from-android-device-monoandroid-using-vs2010

我會推薦的是,您使用實際的雲存儲帳戶而不是存儲模擬器來測試您的代碼。當您使用實際的存儲帳戶時,請使用下面的代碼(顯然請適當更改連接字符串)。它應該工作:

 var connectionString = "http://127.0.0.1/devstoreaccount1/Testowa?st=2015-07-31T11%3A50%3A00Z&se=2017-0‌​8-01T11%3A50%3A00Z&sp=raud&sv=2015-04-05&tn=testowa&sig=UEbinBTgpEGwy1ts0hwmSfELM‌​1lYCBItLHgWpWSgvE4%3D"; 
     CloudTable table = new CloudTable(new Uri(connectionString)); 
     bool exists = await table.ExistsAsync(); 
     if (exists) 
      System.Console.WriteLine("Exists"); 
     else 
      System.Console.WriteLine("Doesnt exist"); 
+0

我在我的設備上運行代碼,而不是仿真器。但最不重要的,我現在知道,這不是SAS的問題,但連接到存儲模擬器。謝謝你的時間:)你真的幫了我 – wasilewitz

+0

當你的設備,你的意思是你的手機或電腦? –

+0

我的手機。通過USB連接 – wasilewitz

相關問題