Azure Function返回500内部服务器错误

我正在尝试练习“ Mastering Xamarin.Forms”第三版中的练习。我已按照书中的说明通过门户添加功能应用程序。

run.csx文件如下:

#r "Newtonsoft.Json"
#r "microsoft.WindowsAzure.Storage"
using System.Net;
using microsoft.AspNetCore.Mvc;
using microsoft.Extensions.Primitives;
using microsoft.WindowsAzure.Storage;
using microsoft.WindowsAzure.Storage.Table;
using Newtonsoft.Json;

public static async Task<IactionResult> Run(HttpRequest req,Newtonsoft.Json.Linq.JArray entryTableInput,IAsyncCollector<Entry> entryTableOutput,ILogger log)
{
    log.LogInformation(req.Method);
    if (req.Method == "GET")
    {
        return (actionResult) new OkObjectResult(entryTableInput);
    }
    var requestBody = await new StreamReader(req.Body).ReadToEndAsync();
    var entry = JsonConvert.DeserializeObject<Entry>(requestBody);

    if (entry != null)
    {
                await entryTableOutput.AddAsync(entry);
        return (actionResult) new OkObjectResult(entry);
    }
    return new BadRequestObjectResult("Invalid entry request.");
}
public class Entry
{
    public string Id => Guid.NewGuid().ToString("n");
    public string Title { get; set; }
    public double Latitude { get; set; }
    public double Longitude { get; set; }
    public DateTime Date { get; set; }
    public int Rating { get; set; }
    public string Notes { get; set; }
    // Required for Table Storage entities
    public string PartitionKey => "ENTRY";
    public string RowKey => Id;
}

function.json:

{
  "bindings": [
    {
      "authLevel": "anonymous","name": "req","type": "httpTrigger","direction": "in"
    },{
      "name": "$return","type": "http","direction": "out"
    },{
      "type": "table","name": "entryTableOutput","tableName": "entry","connection": "AzureWebJobStorage","name": "entryTableInput","take": 50,"connection": "AzureWebJobsStorage","direction": "in"
    }
  ],"disabled": false
}

我正在使用Postman来测试请求。 GET和POST都返回500内部服务器错误。我不知道下一步该怎么做。

liuchun227728 回答:Azure Function返回500内部服务器错误

我不知道您是否找到了所需的答案,但是,以防万一以后有人遇到此帖子(就像我遇到相同错误并且以前没有使用过Azure一样)。

创建 Function (根据上面列出的代码 entry )后,您需要选择集成选项并指定以下内容:

输入
绑定类型:天蓝色表存储
表参数名称: entryTableInput
表格名称:条目
存储帐户连接: AzureWebJobsStorage

输出
绑定类型:天蓝色表存储
表参数名称: entryTableOutput
表格名称:条目
存储帐户连接: AzureWebJobsStorage

此外,转到在设置Azure功能时创建的存储帐户,然后在 Tables 下创建一个名为 输入

然后,您应该发现可以按照书中的说明使用Postman来测试API。

,

我首先尝试在本地运行该函数并在该函数内设置断点。然后,您可以使用Postman触发该功能,逐步调试,然后查看问题所在。将Azure功能部署到Azure时,我还建议启用应用程序见解,您可以使用它来查看引发的异常的详细信息。

本文链接:https://www.f2er.com/2649911.html

大家都在问