Azure 函数:无法将参数“_return”绑定到类型 HttpResponseMessage
Azure functions: Cannot bind parameter '_return' to type HttpResponseMessage
我从 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.).
您现在可以通过将响应输出绑定的名称从 $return
更改为 res
来解决此问题。前者将很快在我们的下一个版本中运行,但现在还没有。看起来我们推出函数模板更新有点太早了 - 我已经在我们的 repo 中为那个问题创建了一个错误 here。谢谢:)
我从 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.).
您现在可以通过将响应输出绑定的名称从 $return
更改为 res
来解决此问题。前者将很快在我们的下一个版本中运行,但现在还没有。看起来我们推出函数模板更新有点太早了 - 我已经在我们的 repo 中为那个问题创建了一个错误 here。谢谢:)