具有Cosmos DB输入的Azure Function HttpTrigger

时间:2019-06-03 07:06:40

标签: c# triggers azure-functions azure-triggers cosmosdbtrigger

我正在尝试使用cosmos DB输入绑定创建一个Azure Function HttpTrigger。 但这给了我一个类型错误。

Http trigger

这是我正在尝试的:

public static async Task<IActionResult> Run(IReadOnlyList<Document> inputDocs, HttpRequest req, IAsyncCollector<Document> outputDocs, ILogger log)
{
}

这给了我以下错误:

2019-06-03T06:48:35.646 [Error] Microsoft.Azure.WebJobs.Host: Error indexing method 'Functions.HttpTrigger1'. Microsoft.Azure.WebJobs.Host: Can't bind CosmosDB to type 'System.Collections.Generic.IReadOnlyList`1[Microsoft.Azure.Documents.Document]'.
Possible causes:
1) Tried binding to 'Microsoft.Azure.Documents.Client.DocumentClient, Microsoft.Azure.DocumentDB.Core, Version=2.2.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' but user type assembly was 'System.Collections.Generic.IReadOnlyList`1[[Microsoft.Azure.Documents.Document, Microsoft.Azure.DocumentDB.Core, Version=2.2.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35]], System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e.
2) Tried binding to 'Newtonsoft.Json.Linq.JArray, Newtonsoft.Json, Version=11.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed' but user type assembly was 'System.Collections.Generic.IReadOnlyList`1[[Microsoft.Azure.Documents.Document, Microsoft.Azure.DocumentDB.Core, Version=2.2.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35]], System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e.
3) Tried binding to 'System.Collections.Generic.IEnumerable`1[[Microsoft.Azure.WebJobs.Extensions.CosmosDB.CosmosDBExtensionConfigProvider+DocumentOpenType, Microsoft.Azure.WebJobs.Extensions.CosmosDB, Version=3.0.3.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35]], System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e' but user type assembly was 'System.Collections.Generic.IReadOnlyList`1[[Microsoft.Azure.Documents.Document, Microsoft.Azure.DocumentDB.Core, Version=2.2.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35]], System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e.

有人可以帮助我吗?

1 个答案:

答案 0 :(得分:2)

请参见此处的示例,该示例几乎就是您正在做的事情:https://docs.microsoft.com/en-us/sandbox/functions-recipes/cosmos-db?tabs=csharp#retrieve-a-list-of-documents

[FunctionName("CosmosDBSample")]
public static HttpResponseMessage Run(
    [HttpTrigger(AuthorizationLevel.Anonymous, "get")] HttpRequestMessage req,
    [DocumentDB("test", "test", ConnectionStringSetting = "CosmosDB", sqlQuery = "SELECT top 2 * FROM c order by c._ts desc")] IEnumerable<object> documents)
{
    return req.CreateResponse(HttpStatusCode.OK, documents);
}