当我 运行 我在门户中的 Azure 函数时出现内部服务器错误
Getting Internal server Error when i run my Azure Function in the Portal
我已经创建并发布了一个 Http 触发的 Azure 可视化函数 studio.The 函数用于连接到物联网集线器并获取模块孪生属性。
我已经使用模块连接字符串配置了 local.settings.json 文件,并且还在门户的应用程序设置中添加了相同的内容。
但是当我 运行 门户中的功能时,它给我 内部服务器错误 500。
我的Azure函数版本运行ning是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();
}
}
我尝试将 运行time 版本从 1 更改为 2,反之亦然。仍然无法正常工作。同样在应用程序设置下,我设置了
WEBSITE_NODE_DEFAULT_VERSION
至 8.11.1.from 6.5.0.
谁能帮我解决这个问题?
HTTP 函数实际上应该是 return 一个 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");
}
我已经创建并发布了一个 Http 触发的 Azure 可视化函数 studio.The 函数用于连接到物联网集线器并获取模块孪生属性。
我已经使用模块连接字符串配置了 local.settings.json 文件,并且还在门户的应用程序设置中添加了相同的内容。 但是当我 运行 门户中的功能时,它给我 内部服务器错误 500。
我的Azure函数版本运行ning是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();
}
}
我尝试将 运行time 版本从 1 更改为 2,反之亦然。仍然无法正常工作。同样在应用程序设置下,我设置了
WEBSITE_NODE_DEFAULT_VERSION
至 8.11.1.from 6.5.0.
谁能帮我解决这个问题?
HTTP 函数实际上应该是 return 一个 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");
}