运行 从 Android 模拟器或 Android 设备连接的 CosmosDB 模拟器

Run CosmosDB Emulator to connect from Android Emulator or Android Device

我的 CosmosDB 模拟器在使用控制台应用程序进行本地测试时运行良好。

我想从我的 Xamarin Android 应用程序连接,无论是在模拟器上还是在同一 LAN 上的设备上。 如果使用模拟器,我使用 CosmosDB 客户端连接到 https://10.0.2.2:8081,在调试控制台中我会看到许多重复的内容:

[0:] DocDBTrace 警告:0 :

[0:]端点不可到达。刷新缓存并重试

如果使用模拟器,使用浏览器,我连接到 https://10.0.2.2:8081/_explorer/index.html 我可以访问 DataExplorer。

我知道我必须启用 /AllowNetworkAccess,所以我关闭了模拟器,删除了 CosmosDBEmulator 数据文件夹,然后:

.\Microsoft.Azure.Cosmos.Emulator.exe /GenKeyFile=cosmo.key

然后用

启动

.\Microsoft.Azure.Cosmos.Emulator.exe /AllowNetworkAccess /KeyFile=cosmo.key

DataExplorer 打开,我尝试创建数据库,但收到此错误:

所以基本上使用 /AllowNetworkAccess 即使使用本地使用的基于 Web 的 DataExplorer,我也会收到错误消息。

我使用 cosmos.key 新密钥从 Android 模拟器尝试我的应用程序,但我收到此错误:

Microsoft.Azure.Cosmos.CosmosException: '响应状态码不表示成功:未授权(401);子状态:0; ActivityId:626ab064-6c6e-445a-883a-8491de96636f;原因:(响应状态码不表示成功:Unauthorized(401);Substatus:0;ActivityId:626ab064-6c6e-445a-883a-8491de96636f;原因:(响应状态码不表示成功:Unauthorized(401);Substatus: 0; ActivityId: 626ab064-6c6e-445a-883a-8491de96636f; 原因: (Message: {"Errors":["The MAC signature found in the HTTP request is not the same as the computed signature. Server used following要签名的字符串 - 'post\ndocs\ndbs/localPlayGround/colls/containerPlayGround\nthu, 05 nov 2020 15:28:15 gmt\n\n'。了解更多信息:https://aka.ms/cosmosdb-tsg-mac-signature"]} ActivityId:626ab064-6c6e-445a-883a-8491de96636f,请求 URI:/apps/DocDbApp/services/DocDbServer1/partitions/a4cb494d-38c8-11e6-8106-8cdcd42c33be/replicas/1p/,RequestStats: RequestStartTime:2020-11-05T15:28:15.8263417Z,RequestEndTime:2020-11-05T15:28:15.8403436Z,区域数attempted:1 ResponseTime: 2020-11-05T15:28:15.8403436Z, StoreResult: StorePhysicalAddress: rntbd://192.168.0.6:10253/apps/DocDbApp/services/DocDbServer1/partitions/a4cb494d-38c8-11e6-8106-8cdcd42c33be/replicas/1p/, LSN: 2, GlobalCommittedLsn: -1, PartitionKeyRangeId:, IsValid: True, StatusCode : 401, SubStatusCode: 0, RequestCharge: 0, ItemLSN: -1, SessionToken: -1#2, UsingLocalLSN: True, TransportException: null, ResourceType: Document, OperationType: Query , SDK: Microsoft.Azure.Documents.Common/2.11.0, 请参见CosmosDiagnostics, Linux/Unknown cosmos-netstandard-sdk/3.14.0););'

对我做错了什么有什么建议吗? CosmosDB 模拟器是 2.11.6

谢谢

If I generate the key, then overwrite it with the default key, and then use the default as a generated key, it works across network.

您需要将生成的密钥替换为默认密钥,数据浏览器才能继续工作。

参考: