mon*_*_za 4 c# pagination azure-functions azure-cosmosdb azure-cosmosdb-sqlapi
我正在运行一个查询 CosmosDB 实例的 Azure 函数。
我正在尝试使用延续令牌实现分页,但在使用延续令牌调用我的函数时不断收到以下响应:
Message": "发生错误。", "ExceptionMessage": "无效的连续令牌\r\nActivityId: 0f79a65f-a9d2-49a8-8a9c-d33a8526bec8,Microsoft.Azure.Documents.Common/2.0.0.0,documentdb-dotnet- 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);
}
}
Run Code Online (Sandbox Code Playgroud)
在我首次调用 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"
}
]
}
Run Code Online (Sandbox Code Playgroud)
当我使用下一个 Azure 函数请求中提供的令牌时,使用带有令牌的 url http://localhost:7071/api/Event/GetAllPaged/3/CDhbANnikwAGAAAAAAAAAA==,我收到上面列出的错误。
我究竟做错了什么?
我发现了我的错误。
我需要将收到的整个延续 json 对象传递回 azure,而不是仅提取令牌。
而不是通过:
CDhbANnikwAGAAAAAAAAAA==
我应该已经传递了返回的整个 JSON 对象/字符串,如下所示:
"{\"令牌\":\"CDhbANnikwAIAAAAAAAAAA==\",\"范围\":{\"min\":\"\",\"max\":\"FF\"}}"
归档时间: |
|
查看次数: |
2445 次 |
最近记录: |