从dll文件运行函数

时间:2018-02-17 13:02:43

标签: c# azure azure-functions

我试图从dll文件运行一个函数,但我收到了这个错误:

  

2018-02-17T12:51:41.403 [错误]执行函数时出现异常:Functions.PreCompiledHttpTrigger。 Microsoft.Azure.WebJobs.Script:发生了一个或多个错误。 System.Web.Http:请求没有关联的配置对象,或者提供的配置为null。

using System.Linq;
using System.Net;
using System.Net.Http;
using System.Threading.Tasks;

namespace CompiledAzureFunctions
{
public class Utility
{
public static async Task<HttpResponseMessage> Run(HttpRequestMessage req)
{
    // parse query parameter
    string name = req.GetQueryNameValuePairs()
        .FirstOrDefault(q => string.Compare(q.Key, "name", true) == 0)
        .Value;

    if (name == null)
    {
        // Get request body
        dynamic data = await req.Content.ReadAsAsync<object>();
        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.json

{
  "scriptFile": "bin/CompiledAzureFunctions.dll",
  "entryPoint": "CompiledAzureFunctions.Utility.Run",
  "bindings": [
    {
      "authLevel": "anonymous",
      "name": "req",
      "type": "httpTrigger",
      "direction": "in",
      "methods": [
        "get",
        "post"
      ]
    },
    {
      "name": "$return",
      "type": "http",
      "direction": "out"
    }
  ],
  "disabled": false
}

0 个答案:

没有答案