【发布时间】:2019-01-02 05:49:46
【问题描述】:
按照本教程chain-azure-functions-data-using-bindings, 使用 JavaScript 时它可以工作,但是使用 .net 作为运行时堆栈创建了一个新的函数应用程序,添加了所需的 cosmos db 映射,当发送带有查询参数的 GET 请求时 https://azurefuncurl?code=abc&id=docs appinsights 显示由于 System.InvalidOperationException 导致 azure 函数/主机无法启动
尝试通过官方文档:azure-functions/configInput-Usage,没有运气
函数.json
{
"bindings": [
{
"authLevel": "function",
"name": "req",
"type": "httpTrigger",
"direction": "in",
"methods": [
"get",
"post"
]
},
{
"name": "$return",
"type": "http",
"direction": "out"
},
{
"type": "cosmosDB",
"name": "bookmark",
"databaseName": "func-io-learn-db",
"collectionName": "Bookmarks",
"connectionStringSetting": "chainazurefunctions_DOCUMENTDB",
"id": "{id}",
"partitionKey": "{id}",
"direction": "in"
}]
}
运行.csx
#r "Newtonsoft.Json"
using System.Net;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Primitives;
using Newtonsoft.Json;
public static async Task<IActionResult> Run(HttpRequest req, ILogger log, dynamic bookmark)
{
log.LogInformation("C# HTTP trigger function processed a request.");
string name = req.Query["id"];
string requestBody = await new StreamReader(req.Body).ReadToEndAsync();
dynamic data = JsonConvert.DeserializeObject(requestBody);
name = name ?? data?.name;
return name != null
? (ActionResult)new OkObjectResult($"Hello, {name}")
: new BadRequestObjectResult("Please pass a name on the query string or in the request body");
}
异常信息:
Error indexing method 'Functions.find-bookmark' Unable to resolve binding parameter 'id'. Binding expressions must map to either a value provided by the trigger or a property of the value the trigger is bound to, or must be a system binding expression (e.g. sys.randguid, sys.utcnow, etc.).
【问题讨论】:
标签: azure azure-functions csx