c# - Azure函数: Cannot bind parameter '_return' to type HttpResponseMessage

标签 c# http azure azure-functions

我从 quickstart guide 创建了基本的 Azure 函数。根据教程,这个默认功能应该立即起作用,但我收到错误。

函数体:

using System.Net;

public static async Task<HttpResponseMessage> Run(HttpRequestMessage req, TraceWriter log)
{
    log.Info("C# HTTP trigger function processed a request.");

    // parse query parameter
    string name = req.GetQueryNameValuePairs()
        .FirstOrDefault(q => string.Compare(q.Key, "name", true) == 0)
        .Value;

    // Get request body
    dynamic data = await req.Content.ReadAsAsync<object>();

    // Set name to query string or body data
    name = name ?? data?.name;

    return name == null
        ? req.CreateResponse(HttpStatusCode.BadRequest, "Please pass a name on the query string or in the request body")
        : req.CreateResponse(HttpStatusCode.OK, "Hello " + name);
}

错误消息:

Function ($HttpTriggerCSharp1) Error: Microsoft.Azure.WebJobs.Host: Error indexing method 'Functions.HttpTriggerCSharp1'. Microsoft.Azure.WebJobs.Host: Cannot bind parameter '_return' to type HttpResponseMessage&. Make sure the parameter Type is supported by the binding. If you're using binding extensions (e.g. ServiceBus, Timers, etc.) make sure you've called the registration method for the extension(s) in your startup code (e.g. config.UseServiceBus(), config.UseTimers(), etc.).

最佳答案

您现在可以通过将响应输出绑定(bind)的名称从 $return 更改为 res 来解决此问题。前者很快就会在我们的下一个版本中运行,但目前还没有。看来我们推出功能模板更新有点太早了 - 我创建了一个错误 here在我们针对该问题的存储库中。谢谢:)

关于c# - Azure函数: Cannot bind parameter '_return' to type HttpResponseMessage,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40590610/

相关文章:

c# - 使用 C# 设置 TreeView ForeColor

c# - 动态性能评价

java - 如何使用 HTTP 和 REST 将 Angular 前端连接到 Java Servlet 后端?

Azure 文件存储 : create share for App Services

azure - CSP 表单操作指令覆盖在 Chrome 中不起作用

c# - MVVM light - 导航服务android

用简单的术语为 wpf mvvm 编写的 c# 类

c - 读取期间通过套接字连接超时获取请求

node.js - Node : close http. 即使服务器发送保持事件状态也得到响应

python - 保持azure管道作业中的postgres docker容器运行