我已经从Visual Studio创建并发布了一个Http触发的Azure函数,该函数用于连接到IoT中心并获取模块的twin属性。
我已经使用模块连接字符串配置了 local.settings.json 文件,并且还在门户网站的应用程序设置中添加了该文件。 但是,当我在门户中运行该功能时,它会给我内部服务器错误500。
我正在运行的Azure功能版本是v1。
我正在使用的json文件:
local.settings.json
new Object(){}.getClass().getEnclosingMethod().getParameterTypes()
host.json
{
"IsEncrypted": false,
"Values": {
"AzureWebJobsStorage": "xxxxxxxx",
"AzureWebJobsDashboard": "xxxxxx",
"FUNCTIONS_WORKER_RUNTIME": "dotnet",
"ModuleConnectionString": "xxxxxxxxx"
}
}
function.json
{
"http": {
"routePrefix": "api",
"maxOutstandingRequests": 20,
"maxConcurrentRequests": 10,
"dynamicThrottlesEnabled": false
},
"version": "2.0"
}
以下是代码:
function1.cs
{
"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"
}
twin.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();
}
}
我尝试将运行时版本从1更改为2,反之亦然。仍然无法正常工作。同样在“应用程序设置”下,我已设置
WEBSITE_NODE_DEFAULT_VERSION
从6.5.0到8.11.1。有人可以帮我解决这个问题吗?
答案 0 :(得分:1)
HTTP Function应该实际上返回HTTP结果,请尝试将Function更改为
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");
}