首页 文章

无效的Continuation令牌CosmosDB

提问于
浏览
1

我正在运行Azure函数,它查询CosmosDB的实例 .

我正在尝试使用Continuation Token实现分页,但在使用continuation token调用我的函数时,我继续得到以下响应:

消息“:”发生错误 . “,”ExceptionMessage“:”无效的连续令牌\ r \ nActivityId:0f79a65f-a9d2-49a8-8a9c-d33a8526bec8,Microsoft.Azure.Documents.Common / 2.0.0.0,documentdb-netnet -sdk / 1.22.0主机/ 32位MicrosoftWindowsNT / 6.2.9200.0

这是我的Azure功能:最初将调用此函数而不使用令牌,并且根据第二页的请求,将传递令牌 .

[FunctionName("GetAllPaged")]
public static async Task<HttpResponseMessage> ReadAll(
    [HttpTrigger(AuthorizationLevel.Function, "get", Route = "GetAllPaged/{pageSize?}/{token?}")]HttpRequestMessage req,
    int? pageSize, string token, ILogger log, [Inject]IComponent<EventModel> component)
{
    try
    {
        log.LogInformation("Get all events");

        var response = await component.GetAll_Paged(pageSize, token);

        return req.CreateResponse(HttpStatusCode.OK, response);
    }
    catch (Exception ex)
    {
        log.LogError(ex.Message, ex);
        return req.CreateErrorResponse(HttpStatusCode.BadRequest, ex);
    }
}

在我初次调用我的Azure函数时,使用url http://localhost:7071/api/Event/GetAllPaged/3,我收到以下响应:

{
"Continuation": {
    "token": "CDhbANnikwAGAAAAAAAAAA==",
    "range": {
        "min": "",
        "max": "FF"
    }
},
"Results": [
    {
        "id": "c428e1c4-48d5-47ae-9f37-c29cc3fc8696",
        "Description": "Test description nr: 64791",
        "User": "Test User"
    },
    {
        "id": "bab08fe7-da5c-48c6-971d-a14ef3eb5f4c",
        "Description": "Test description nr: 63486",
        "User": "Test User"
    },
    {
        "id": "9688acc2-4acf-4acd-a252-5481b5b4d450",
        "Description": "Test description nr: 86498",
        "User": "Test User"
    }
]
}

当我使用我的下一个Azure功能请求中提供的令牌时,使用带有令牌http://localhost:7071/api/Event/GetAllPaged/3/CDhbANnikwAGAAAAAAAAAA==的URL,我得到上面列出的错误 .

我究竟做错了什么?

1 回答

  • 1

    我发现了自己的错误 .

    我需要将收到的整个延续json对象传递回azure,而不是仅提取令牌 .

    而不是通过:

    CDhbANnikwAGAAAAAAAAAA ==

    我应该通过返回的整个JSON对象/字符串,如下所示:

    “{\”token \“:\”CDhbANnikwAIAAAAAAAAAA == \“,\”range \“:{\”min \“:\”\“,\”max \“:\”FF \“}}”

相关问题