在Portal中运行Azure功能时出现内部服务器错误

问题描述 投票:0回答:1

我已经从visual studio创建并发布了一个Http触发的Azure功能。该功能用于连接到iot hub并获得模块的两个属性。

我已经使用模块连接字符串配置了local.settings.json文件,并在门户网站的应用程序设置中添加了相同的文件。但是当我在门户网站中运行该功能时,它给我内部服务器错误500。

我正在运行的Azure功能版本是v1。

我正在使用的json文件:

local.settings.json

{
      "IsEncrypted": false,
      "Values": {
        "AzureWebJobsStorage": "xxxxxxxx",
        "AzureWebJobsDashboard": "xxxxxx",
        "FUNCTIONS_WORKER_RUNTIME": "dotnet",
        "ModuleConnectionString": "xxxxxxxxx"
      }
    }

host.json

{
  "http": {

"routePrefix": "api",

"maxOutstandingRequests": 20,

"maxConcurrentRequests": 10,

"dynamicThrottlesEnabled": false

    },

 "version": "2.0"

}

function.json

{
  "generatedBy": "Microsoft.NET.Sdk.Functions-1.0.19",
  "configurationSource": "attributes",
  "bindings": [
    {
      "type": "httpTrigger",
      "methods": [
        "get",
        "post"
      ],
      "authLevel": "function",
      "name": "req"
    }
  ],
  "disabled": false,
  "scriptFile": xxxx.dll",
  "entryPoint": "xxxxxxxx.Run"
}

以下是代码:

function1.cs

    public static class Function1
    {
        [FunctionName("Function1")]
        public static async Task Run([HttpTrigger(AuthorizationLevel.Function, "get", "post", Route = null)]HttpRequest req, ILogger log)
        {
            log.LogInformation("C# HTTP trigger function processed a request.");


            var moduleConnectionString = Environment.GetEnvironmentVariable("ModuleConnectionString", EnvironmentVariableTarget.Process);


            ModuleClient _moduleClient = ModuleClient.CreateFromConnectionString(moduleConnectionString, TransportType.Amqp);

            var sample = new TwinSample(_moduleClient);
            await sample.RunSampleAsync();
       }
    }

twin.cs

class TwinSample
    {

        private ModuleClient _moduleClient;


        public TwinSample(ModuleClient moduleClient)
        {
            this._moduleClient = _moduleClient;
        }


        public async Task<string> RunSampleAsync()
        {
            Console.WriteLine("Retrieving twin...");
            Twin twin = await _moduleClient.GetTwinAsync().ConfigureAwait(false);

            Console.WriteLine("\tInitial twin value received:");

            Console.WriteLine($"\t{twin.ToJson()}");
            return twin.ToJson();
        }
    }

我尝试将运行时版本从1更改为2,反之亦然。仍然没有用。同样在应用程序设置我已设置

WEBSITE_NODE_DEFAULT_VERSION

从6.5.0到8.11.1。

任何人都可以帮我解决这个问题吗?

azure azure-functions azure-functions-runtime azure-functions-core-tools
1个回答
1
投票

HTTP函数应该实际返回HTTP结果,尝试将函数更改为

public static async Task<HttpResponseMessage> Run(
    [HttpTrigger(AuthorizationLevel.Function, "get", "post", Route = null)] HttpRequestMessage req, 
    ILogger log)
{
    // your code goes here
    return req.CreateResponse(HttpStatusCode.OK, "Done");
}
© www.soinside.com 2019 - 2024. All rights reserved.