代码之家  ›  专栏  ›  技术社区  ›  Carlos Rodriguez

Azure函数参数中的DocumentClient绑定

  •  3
  • Carlos Rodriguez  · 技术社区  · 7 年前

    我正在F#中编写一个http触发器Azure函数,我想绑定一个类型为的参数 DocumentClient

    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"
          }
        }
      }
    }
    

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

    我正在使用development storage和Cosmos DB emulator在本地运行该函数。我试着把它的描述翻译成F here here . 但我只知道错误 Microsoft.Azure.WebJobs.Extensions.DocumentDB: 'Id' is required when binding to a DocumentClient property

    1 回复  |  直到 7 年前
        1
  •  5
  •   Community CDub    4 年前

    中提到了一种变通方法 this issue on Github . 它固定在 tooling 并将在下一版本中提供

    我发现了问题并提交了 https://github.com/Azure/azure-functions-cli/issues/206 更新之前的解决方法:

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

    func.exe.config 在记事本中。

    <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>
    

    在两个位置,更换 1.11.0.0 具有 1.13.0.0

    <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>
    

    保存并重试。