Car*_*uez 2 f# azure azure-webjobssdk azure-functions azure-cosmosdb
我在F#中编写一个http触发器Azure函数,我想绑定一个类型的参数,DocumentClient以便更好地控制在Cosmos DB中完成的查询.这是我到目前为止:
Function.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)
Run Code Online (Sandbox Code Playgroud)
function.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"
}
]
}
Run Code Online (Sandbox Code Playgroud)
host.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"
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
local.settings.json
{
"IsEncrypted": false,
"Values": {
"AzureWebJobsDashboard": "",
"AzureWebJobsStorage": "UseDevelopmentStorage=true",
"COSMOSDB_CONNECTION_STRING": "AccountEndpoint=https://localhost:8081;AccountKey=C2y6yDjf5/R+ob0N8A7Cgv30VRDJIWEHLM+4QDU5DE2nQ9nDuVTqobD4b8mGGyPMbIZnqyMsEcaGQy67XIw/Jw==;"
}
}
Run Code Online (Sandbox Code Playgroud)
我使用开发存储和Cosmos DB模拟器在本地运行该函数.我试图转换为F#它描述这里为C#.它也与这里提到的几乎相同.但我只得到错误Microsoft.Azure.WebJobs.Extensions.DocumentDB: 'Id' is required when binding to a DocumentClient property.
这个问题在Github上有一个解决方法.它已在工具中修复,并将在下一个版本中提供
从github复制的解决方法
我发现了这个问题并提交了 https://github.com/Azure/azure-functions-cli/issues/206.在我们进行更新之前,最简单的解决方法是:
去吧
C:\Users\{user}\appdata\local\Azure.Functions.Cli\1.0.0.
func.exe.config在记事本中打开.找到这个:
Run Code Online (Sandbox Code Playgroud)<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所以你最终得到:Run Code Online (Sandbox Code Playgroud)<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>保存并重试.
| 归档时间: |
|
| 查看次数: |
541 次 |
| 最近记录: |