【发布时间】:2019-06-05 17:43:39
【问题描述】:
是否可以(输入)绑定到 http 触发函数中的表存储?
我正在尝试将输入绑定添加到具有以下属性的常规 http 触发函数内的 table-storage:
[Table("MyTable", "MyPartition", "{httpTrigger}")] MyPoco poco
但是当我执行它时它返回以下错误:
[2019 年 6 月 5 日下午 5:36:38] 发生了未处理的主机错误。 [2019 年 6 月 5 日 下午 5:36:38] Microsoft.Azure.WebJobs.Host: 无法从 Azure 调用“tableStorageInputBindingHttpTriggered” 网络作业 SDK。是否缺少 Azure WebJobs SDK 属性?
另外在启动时,我得到这个异常:
[2019 年 6 月 5 日下午 6:17:17] tableStorageInputBindingHttpTriggered:Microsoft.Azure.WebJobs.Host:错误索引方法“tableStorageInputBindingHttpTriggered”。 Microsoft.Azure.WebJobs.Host:无法解析绑定参数“httpTrigger”。绑定表达式必须映射到触发器提供的值或触发器绑定到的值的属性,或者必须是系统绑定表达式(例如 sys.randguid、sys.utcnow 等)。
这是完整的功能:
public class MyPoco
{
public string PartitionKey { get; set; }
public string RowKey { get; set; }
public string Directory { get; set; }
}
public static class tableStorageInputBindingHttpTriggered
{
[FunctionName("tableStorageInputBindingHttpTriggered")]
public static async Task<IActionResult> Run(
[HttpTrigger(AuthorizationLevel.Function, "get", "post", Route = null)] HttpRequest req,
[Table("MyTable", "MyPartition", "{httpTrigger}")] MyPoco poco,
ILogger log)
{
string name = req.Query["name"];
string requestBody = await new StreamReader(req.Body).ReadToEndAsync();
dynamic data = JsonConvert.DeserializeObject(requestBody);
name = name ?? data?.name;
return name != null
? (ActionResult)new OkObjectResult($"PK={poco.PartitionKey}, RK={poco.RowKey}, Text={poco.Directory}")
: new BadRequestObjectResult("");
}
}
我做错了什么?如何绑定到 http 触发的 azure 函数中的表存储?
【问题讨论】:
-
你能分享你的计划吗,你到底想做什么?
-
对于每个http请求,我希望将请求的bbody添加到表存储中
-
让我验证你想在调用 http 触发器时在表存储中读写?
-
@MdFaridUddinKiron 我想阅读(这是与表存储的输入绑定)
-
请看一下。我试过这种方法。如果对你有帮助。很抱歉,我答复晚了。谢谢,编码愉快!
标签: c# .net azure azure-functions azure-table-storage