azure - 如何将 Microsoft Azure 存储模拟器与 Xamarin 结合使用?

标签 azure xamarin xamarin.android azure-storage azure-table-storage

如何将 Microsoft Azure 存储模拟器与 Xamarin.Android 结合使用? 我已下载 Microsoft Azure 存储模拟器和 Microsoft Azure 存储资源管理器。我尝试按照 Microsoft 网站上的教程进行操作,但仍然遇到身份验证问题。当我在免费试用订阅期间使用 real 时,一切正常。

我知道我必须使用 SAS key 。但是当我在存储资源管理器中创建表存储然后生成 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>

感谢您的宝贵时间。

最佳答案

我相信您收到此错误是因为您在模拟器中运行此代码。由于模拟器的 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");

关于azure - 如何将 Microsoft Azure 存储模拟器与 Xamarin 结合使用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38682876/

相关文章:

c# - Azure 离线同步。无法添加项目 "Query execution failed with result: ' MISMATCH'。”

c# - 如何在 xamarin.forms 中读取图像源或图像名称?

javascript - NodeJS - 直接流式传输到 Azure 数据湖

azure - Azure 函数参数中的 DocumentClient 绑定(bind)

c# - 为什么要更改后退按钮的标题?

linq - Xamarin Forms - 如何从 MergedDictionaries 中选择 C# 中的资源

xamarin - 如何使用 Plugin.Store Review 在 Xamarin 表单应用程序中的 App Store 上请求评论?

android - Xamarin/Android 应用程序 : Broadcast receiver not working

azure - 将变量从 --extra-vars 传递到角色中

mongodb - 使用 MongoDB API 连接到 CosmosDB 时出现超时错误