我用向导创建了一个简单的HttpTrigger Azure函数,使用VS 17 15.3(带有nuget包Microsoft.NET.Sdk.Functions 1.0.2)。它给了我下面的代码:Azure函数 - VS2017工具 - 在函数.json中缺少绑定
public static class Function1
{
[FunctionName("Function1")]
public static HttpResponseMessage Run([HttpTrigger(AuthorizationLevel.Anonymous, "get", "post", Route = "HttpTriggerCSharp/name/{name}")]HttpRequestMessage req, string name, TraceWriter log)
{
log.Info("C# HTTP trigger function processed a request.");
// Fetching the name from the path parameter in the request URL
return req.CreateResponse(HttpStatusCode.OK, "Hello " + name);
}
}
当我运行在VS调试模式的功能,并与邮差调用它,它的正常工作,我有身体反应。
当我启动相同的功能,使用CLI:func host启动并用post man调用它时,函数不返回正文。我有一个空的内容的Http 200。 :(
我发现,在产生function.json
,没有HTTP进行绑定。我产生function.json
{
"generatedBy": "Microsoft.NET.Sdk.Functions-1.0.0.0",
"configurationSource": "attributes",
"bindings": [
{
"type": "httpTrigger",
"route": "HttpTriggerCSharp/name/{name}",
"methods": [ "get", "post" ],
"authLevel": "anonymous",
"name": "req"
}
],
"disabled": false,
"scriptFile": "..\\bin\\FunctionApp1.dll",
"entryPoint": "FunctionApp1.Function1.Run"
}
当我添加了HTTP进行结合,它的正常工作使用FUNC主机启动
{
"generatedBy": "Microsoft.NET.Sdk.Functions-1.0.0.0",
"configurationSource": "attributes",
"bindings": [
{
"type": "httpTrigger",
"route": "HttpTriggerCSharp/name/{name}",
"methods": [ "get", "post" ],
"authLevel": "anonymous", "name": "req"
},
{
"type": "http",
"direction": "out",
"name": "res"
}
],
"disabled": false,
"scriptFile": "..\\bin\\FunctionApp1.dll",
"entryPoint": "FunctionApp1.Function1.Run"
}
这是非常奇怪的是,在调试模式下,它的工作,而不是直接使用CLI ...
感谢您的帮助
请确保您使用的是最新版本的CLI(1.0.2) – ahmelsayed