0
votes

My CosmosDB emulator works well when tested locally with a console application.

I want to connect from my Xamarin Android application, be it on the emulator or on a device on the same LAN. If with the emulator I connect to https://10.0.2.2:8081 with the CosmosDB client, in the debug console I see many repeated:

[0:] DocDBTrace Warning: 0 :

[0:] Endpoint not reachable. Refresh cache and retry

If with the emulator, with the browser, I connect to https://10.0.2.2:8081/_explorer/index.html I can access the DataExplorer.

enter image description here

I understood that I have to enable the /AllowNetworkAccess, so I shut down the emulator, deleted the CosmosDBEmulator data folder, and then:

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

and then launched with

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

DataExplorer opens, and I try to create a db, but I receive this error:

enter image description here

So basically with /AllowNetworkAccess I receive an error even with its own web based DataExplorer, used locally.

I tried my app from the Android emulator, using the cosmos.key new key, and I get this error:

Microsoft.Azure.Cosmos.CosmosException: 'Response status code does not indicate success: Unauthorized (401); Substatus: 0; ActivityId: 626ab064-6c6e-445a-883a-8491de96636f; Reason: (Response status code does not indicate success: Unauthorized (401); Substatus: 0; ActivityId: 626ab064-6c6e-445a-883a-8491de96636f; Reason: (Response status code does not indicate success: Unauthorized (401); Substatus: 0; ActivityId: 626ab064-6c6e-445a-883a-8491de96636f; Reason: (Message: {"Errors":["The MAC signature found in the HTTP request is not the same as the computed signature. Server used following string to sign - 'post\ndocs\ndbs/localPlayGround/colls/containerPlayGround\nthu, 05 nov 2020 15:28:15 gmt\n\n'. Learn more: https://aka.ms/cosmosdb-tsg-mac-signature"]} ActivityId: 626ab064-6c6e-445a-883a-8491de96636f, Request 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, Number of regions 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, Please see CosmosDiagnostics, Linux/Unknown cosmos-netstandard-sdk/3.14.0);););'

Any suggestion on what am I doing wrong? CosmosDB Emulator is 2.11.6

Thanks

1
The error message said that you are Unauthorized. An Unauthorized request means the Authorization header for the request is invalid.Jack Hua
Thanks I've read the error message, but I'm using the CosmosDB client, not making the request manually, and the same code, with the emulator, locally works, and from another client on the lan gives this error. Moreover, as stated in the message, if I /AllowNetworkAccess, I get an error message even using locally the web based DataExplorer Moreover, with the sameMattia Durli
Can you have a look at this thread and check if it helps.Jack Hua
Thanks! it helped. It seems that if I use a generated key, as stated in the documentation, it doesn't work. 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.Mattia Durli
I summarized the answer and can you please accept it (click the ☑️ in the upper left corner of this answer ) so that we can help more people with same problem:).Jack Hua

1 Answers

0
votes

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.

You need to replace your generated key with the default key for the data explorer to continue working.

Refer: azure-cosmos-db-emulator-unauthorized