2017-08-27 26 views
1

我用向导创建了一个简单的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 ...

感谢您的帮助

+0

请确保您使用的是最新版本的CLI(1.0.2) – ahmelsayed

回答

1

当我启动相同的功能时,使用CLI:func host启动并用post man调用它,该函数不返回正文。我有一个空的内容

我创建了一个httpTrigger Azure的功能应用的HTTP 200,而当在调试模式下运行它,我可以得到响应体。

如果我使用CLI func host start来运行函数,我也可以按预期得到响应正文。

enter image description here

请求&响应

enter image description here

此外,根据我的测试(删除HTTP出结合),如果HTTP绑定出在function.json丢失,这将在响应主体中空白内容。

:这个问题不能在我身边(微软的Visual Studio 2017年企业预览(3)版本15.3.0预览7.0)进行复制。但是,对于这个问题,正如你所做的那样,手动添加http输出绑定将是解决问题的一种解决方法。此外,如果可能的话,您可以发布GitHub issue并包含标题“CLI:”。