gpt4 book ai didi

azure - Azure 函数参数中的 DocumentClient 绑定(bind)

转载 作者:行者123 更新时间:2023-12-01 06:57:23 26 4
gpt4 key购买 nike

我正在 F# 中编写一个 http 触发器 Azure 函数,我想绑定(bind)一个 DocumentClient 类型的参数,以便更好地控制在 Cosmos DB 中执行的查询。这是我到目前为止所拥有的:

函数.fs

namespace Functions

open System
open System.Net
open System.Net.Http
open Newtonsoft.Json
open Microsoft.Azure.Documents
open Microsoft.Azure.Documents.Client
open Microsoft.Azure.WebJobs
open Microsoft.Azure.WebJobs.Host
open Microsoft.Azure.WebJobs.Extensions
open Microsoft.Azure.WebJobs.Extensions.DocumentDB

module Function =
let Run(req: HttpRequestMessage, [<DocumentDB>] client: DocumentClient, log: TraceWriter) =
log.Info(sprintf "F# HTTP trigger function processed a request.")
req.CreateResponse(HttpStatusCode.OK)

函数.json

{
"disabled": false,
"scriptFile": "..\\..\\..\\build\\Debug\\Functions\\Functions.dll",
"entryPoint": "Functions.Function.Run",
"bindings": [
{
"direction": "in",
"type": "httpTrigger",
"authLevel": "anonymous",
"name": "req",
"methods": [ "get" ],
"route": "users"
},
{
"direction": "in",
"type": "documentDB",
"name": "client",
"connection": "COSMOSDB_CONNECTION_STRING"
},
{
"direction": "out",
"type": "http",
"name": "res"
}
]
}

主机.json

{
"frameworks": {
"net46":{
"dependencies": {
"Dynamitey": "1.0.2",
"FSharp.Interop.Dynamic": "3.0.0",
"Microsoft.Azure.DocumentDB": "1.17.0",
"Microsoft.Azure.WebJobs.Extensions.DocumentDB": "1.0.0"
}
}
}
}

本地.settings.json

{
"IsEncrypted": false,
"Values": {
"AzureWebJobsDashboard": "",
"AzureWebJobsStorage": "UseDevelopmentStorage=true",
"COSMOSDB_CONNECTION_STRING": "AccountEndpoint=https://localhost:8081;AccountKey=C2y6yDjf5/R+ob0N8A7Cgv30VRDJIWEHLM+4QDU5DE2nQ9nDuVTqobD4b8mGGyPMbIZnqyMsEcaGQy67XIw/Jw==;"
}
}

我正在使用开发存储和 Cosmos DB 模拟器在本地运行该函数。我尝试将其描述的内容翻译为 F# here对于 C#。而且它也与提到的here几乎相同。 。但我只收到错误 Microsoft.Azure.WebJobs.Extensions.DocumentDB:绑定(bind)到 DocumentClient 属性时需要“Id”

最佳答案

this issue on Github 中提到了一种解决方法。它已修复在tooling中并将在下一个版本中提供

从 github 复制的解决方法

I found the issue and filedhttps://github.com/Azure/azure-functions-cli/issues/206. The easiestworkaround until we have an update:

Go to C:\Users\{user}\appdata\local\Azure.Functions.Cli\1.0.0.

Open func.exe.config in notepad.

Find this:

<dependentAssembly>
<assemblyIdentity name="Microsoft.Azure.Documents.Client" publicKeyToken="31bf3856ad364e35" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-1.11.0.0" newVersion="1.11.0.0" />
</dependentAssembly>

In both places, replace 1.11.0.0 with 1.13.0.0 so you end up with:

<dependentAssembly>
<assemblyIdentity name="Microsoft.Azure.Documents.Client" publicKeyToken="31bf3856ad364e35" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-1.13.0.0" newVersion="1.13.0.0" />
</dependentAssembly>

Save and retry.

关于azure - Azure 函数参数中的 DocumentClient 绑定(bind),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45804576/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com