【问题标题】:Azure Storage Library Client on Windows 10 Iot/UWP?Windows 10 Iot/UWP 上的 Azure 存储库客户端?
【发布时间】:2016-01-04 15:44:17
【问题描述】:

Windows 10 Iot-Core/UWP (RPi) 似乎不支持 Azure 存储客户端。但是,我将它用于 Blob,它也用于表格。现在,在更新到最新的稳定版(和-pre,两者都尝试过)之后,对 Tables 的访问会挂在

await table.ExecuteQuerySegmentedAsync(query, new TableContinuationToken());

我徒劳地寻找一种方法来使这个同步,至少可以帮助我调试它。我还想知道其他人目前的成功以及在 IoT-Core (RPi) 上使用 Azure 存储客户端的“独家新闻”。

更新: 扩展 RequestOptions 如下,我的简单调用也如下所示。我仔细检查了连接字符串、表访问(来自其他工具)和帐户。所有这些都可以在其他地方正常工作。我还将 VStudio2015 远程调试中遇到的异常粘贴到 IoT-Core RaspberryPi 最新版本。

        // Setup the table container
        // connectString looks fine, works fine elsewhere: http for debug instead of https 
        var connectionString = @"DefaultEndpointsProtocol=http;AccountName=myaccount;AccountKey=EUybijab+WHATEVERDzYubKGADwjf/6k5IuoRVgPMMqMez0gb07/dfAv9Qj1/v7NkstGAygWNab07q6FhNBQ==";

        var cloudStorageAccount = CloudStorageAccount.Parse(connectionString);
        CloudTableClient cloudTableClient = cloudStorageAccount.CreateCloudTableClient();
        cloudTable = cloudTableClient.GetTableReference(appSettings.AzureStorageOeConfigTableName);
        //never returns var x = await cloudTable.CreateIfNotExistsAsync();

        // Simplest query to existing small table
        var pkey = "b8-27-eb-86-5d-4d";
        var rkey = "0000000013505717";
        var tstOp = TableOperation.Retrieve(pkey, rkey);
        var requestOptions = new TableRequestOptions
        {
            PayloadFormat = TablePayloadFormat.JsonFullMetadata,
            LocationMode = LocationMode.PrimaryThenSecondary,
            RetryPolicy = new ExponentialRetry(),
            ServerTimeout = TimeSpan.FromMinutes(2)
        };
        // Throws exceptions shown below.
        var tst1 = await table.ExecuteAsync(tstOp, requestOptions, null);

例外:对我的测试代码有任何想法或修改吗?

{"<?xml version=\"1.0\" encoding=\"utf-16\"?>\r\n<!--An exception has occurred. For more information please deserialize this message via RequestResult.TranslateFromExceptionMessage.-->\r\n<RequestResult>\r\n  <HTTPStatusCode>403</HTTPStatusCode>\r\n  <HttpStatusMessage>Server failed to authenticate the request. Make sure the value of Authorization header is formed correctly including the signature.</HttpStatusMessage>\r\n  <TargetLocation>Primary</TargetLocation>\r\n  <ServiceRequestID>c4892c5a-0002-003a-4992-493991000000</ServiceRequestID>\r\n  <ContentMd5 />\r\n  <Etag />\r\n  <RequestDate>Wed, 06 Jan 2016 22:30:01 GMT</RequestDate>\r\n  <StartTime>Wed, 06 Jan 2016 21:29:55 GMT</StartTime>\r\n  <EndTime>Wed, 06 Jan 2016 21:32:12 GMT</EndTime>\r\n  <Error>\r\n    <Code>AuthenticationFailed</Code>\r\n    <Message>Server failed to authenticate the request. Make sure the value of Authorization header is formed correctly including the signature.\r\nRequestId:c4892c5a-0002-003a-4992-493991000000\r\nTime:2016-01-07T21:30:36.1204037Z</Message>\r\n  </Error>\r\n  <ExceptionInfo>\r\n    <Type>StorageException</Type>\r\n    <HResult>-2147467259</HResult>\r\n    <Message>Cannot access a closed Stream.</Message>\r\n    <Source />\r\n    <StackTrace />\r\n    <InnerExceptionInfo>\r\n      <ExceptionInfo>\r\n        <Type>ObjectDisposedException</Type>\r\n        <HResult>-2146232798</HResult>\r\n        <Message>Cannot access a closed Stream.</Message>\r\n        <Source>mscorlib</Source>\r\n        <StackTrace>   at System.IO.__Error.StreamIsClosed()\r\n   at System.IO.BufferedStream.ReadAsync(Byte[] buffer, Int32 offset, Int32 count, CancellationToken cancellationToken)\r\n   at System.Net.Http.DelegatingStream.ReadAsync(Byte[] buffer, Int32 offset, Int32 count, CancellationToken cancellationToken)\r\n   at Microsoft.WindowsAzure.Storage.Core.Util.StreamExtensions.&lt;WriteToAsync&gt;d__3`1.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n   at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd(Task task)\r\n   at Microsoft.WindowsAzure.Storage.Core.Executor.Executor.&lt;ExecuteAsyncInternal&gt;d__c`1.MoveNext()</StackTrace>\r\n      </ExceptionInfo>\r\n    </InnerExceptionInfo>\r\n  </ExceptionInfo>\r\n</RequestResult>"}

【问题讨论】:

  • 首先,您始终可以使用 REST API - 客户端库只是它的包装器。其次,为什么你认为制作“同步”的东西会更容易调试而不是更难await ... 没有任何魔法,它等待一个已经异步的操作。 HTTP 调用即使在桌面上也是异步的——这实际上是一种操作系统技巧,使它们看起来是同步的。您是否尝试过将代码包装在 try/catch 块中并记录异常?你等了多久才回电话?你使用了什么超时值?
  • 谢谢。是的,我已经将 REST API 用于 IoT 核心上的服务总线,它只是使用客户端库更简单。是的,试一试/抓住。在 IoT 核心 ARM 平台上,调用只是挂起、永不返回,也不会引发异常。我已经打开了所有可见的东西,包括 CLR 异常。就挂了。无法解释,因为它正在工作......
  • 请求可能耗时过长,或导致重试次数过多。您是否尝试过使用MaximumExecutionTimeServerTimeout 设置传递TableRequestOptions object
  • 用测试代码和返回的异常更新了问题(VisualStudio 2015 远程调试器)。任何想法表示赞赏。由于我使用此存储库来管理同一 IoT 核心应用程序中的 blob,因此我仍然希望将它(而不是 REST)用于我的表。
  • 似乎是同一个问题:stackoverflow.com/questions/32363906/…

标签: c# azure azure-storage azure-table-storage windows-10-iot-core


【解决方案1】:

是的,很遗憾,存储尚不支持 UWP 应用,因为 UWP 平台中存在导致身份验证问题的错误。我们正在等待 UWP 团队的修复。谢谢!

【讨论】:

  • 请在这个频道上告诉我们。谢谢!
猜你喜欢
  • 1970-01-01
  • 2022-12-15
  • 2021-02-17
  • 2019-12-26
  • 2011-02-07
  • 1970-01-01
  • 2019-05-29
  • 2013-08-26
  • 2018-06-25
相关资源
最近更新 更多