我用嚮導創建了一個簡單的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