1
votes

I have tried to read the documents from the CosmosDb collection using Primary Key and Primary Read Only Key using the below code.

    DocumentClient _documentRUClient = new DocumentClient(new Uri(EndPointURI), PrimaryKey);
    DocumentClient _documentRClient = new DocumentClient(new Uri(EndPointURI), 
                                                          ReadOnly_PrimaryKey);

    var result = _documentRUClient.CreateDocumentQuery<T>
                (UriFactory.CreateDocumentCollectionUri(DataBaseId, CollectionId), 
                new FeedOptions() { EnableCrossPartitionQuery = true}).AsEnumerable().ToList();

    var result2 = _documentRClient.CreateDocumentQuery<T>
                (UriFactory.CreateDocumentCollectionUri(DataBaseId, CollectionId), 
                new FeedOptions() { EnableCrossPartitionQuery = true}).AsEnumerable().ToList();

The DocumentClient which uses the Primary Key retrieves the documents from Cosmos DB collection without any issues. But the one which uses the Primary Read Only Key throws the following error.

The input authorization token can't serve the request. Please check that the expected payload is built as per the protocol, and check the key being used. Server used the following payload to sign: 'get

sat, 03 mar 2018 06:47:04 gmt

' ActivityId: d57786a0-f7a0-46e9-9375-d5251b81b1e3, Microsoft.Azure.Documents.Common/1.20.108.4, documentdb-dotnet-sdk/1.20.2 Host/64-bit MicrosoftWindowsNT/10.0.16299.0

How to overcome this issue?

1
Can you edit your question and include the complete error message. The payload is cut off. - Gaurav Mantri
@GauravMantri. Updated the question with complete error message. - Saravana Kumar
@SaravanaKumar Have you checked the key? Any progress? - Jay Gong
@SaravanaKumar Hi,any updates now? - Jay Gong
@JayGong. Right now we are working with RW Keys. I'll check and give you the updates soon. - Saravana Kumar

1 Answers

1
votes

I reproduced your issue when I set the wrong Read-Only key.

Sample code:

using Microsoft.Azure.Documents.Client;
using System;
using System.Linq;

namespace ConsoleApp2
{
    class Program
    {
        private static DocumentClient client;

        static string endpoint = "https://***.documents.azure.com:443/";

        static string key1 = "***";

        static string DataBaseId = "db";
        static string CollectionId = "coll";

        static void Main(string[] args)
        {
            client = new DocumentClient(new Uri(endpoint), key1);

            var result = client.CreateDocumentQuery
                (UriFactory.CreateDocumentCollectionUri(DataBaseId, CollectionId),
                new FeedOptions() { EnableCrossPartitionQuery = true }).AsEnumerable().ToList();

            Console.WriteLine("aaa");

            Console.ReadLine();
        }
    }
}

return message:

enter image description here

I suggest you catch messages via Fiddler and check if your read-only key is correct.

Hope it helps you.