c# - Azure Function Post C# 不以大体执行

标签 c# azure azure-functions

我目前正在实现一个 Azure Function App,它公开了一些函数(主要是 get)。

以下代码似乎有问题:

using System;
using System.Collections.Specialized;
using System.Net;
using Microsoft.Azure.Functions.Worker;
using Microsoft.Azure.Functions.Worker.Http;
using Microsoft.Extensions.Logging;
using System.Net.Http;
using InternalVacanciesAzureFunction.Model;
using Microsoft.Extensions.Options;
using System.Text.Json;
using System.Collections.Generic;

namespace IVAFunction
{
    public class PostFunction
        {
            private readonly HttpClient _httpClient;
    
            public PostFunction(IHttpClientFactory httpClientFactory)
            {
                _httpClient = httpClientFactory.CreateClient();
            }
    
            [Function("postFunction")]
            public HttpResponseData Run([HttpTrigger(AuthorizationLevel.Anonymous, "post", "put")] HttpRequestData req,
                FunctionContext executionContext)
            {
                ILogger logger = executionContext.GetLogger("PostFunction");
                logger.LogError("Code hit: PostFunction.cs");
               
                HttpResponseData response = req.CreateResponse();
                
                string body = new System.IO.StreamReader(req.Body).ReadToEnd();
    
                JsonResponse data = Nfunction.postFunction(_httpClient, "/PostFunction", body, logger, requestPrincipalName);
                if (data.responseType.Equals(ResponseType.OK))
                {
                    response.StatusCode = HttpStatusCode.OK;
                }
                else
                {
                    response.StatusCode = HttpStatusCode.InternalServerError;
                }
    
                response.Headers.Add("Content-Type", "application/json; charset=utf-8");
                response.WriteString(data.json);
    
                return response;
            }
        }
    }

发布到此函数的数据是一个 JSON,其中两个字段中包含 BASE64 编码的字符串。这两个字段的最大大小均为 1.5MB。每次我发布一些小东西,例如2 x 400B,一切顺利。但是当我发送类似 2 x 900kB 的内容时,日志记录显示如下:

2021-12-07T07:42:28.455 [Debug] Request successfully matched the route with name 'postFunction' and template 'api/postFunction'

2021-12-07T07:42:29.129 [Information] Executing 'Functions.postFunction' (Reason='This function was programmatically called via the host APIs.', Id=xxxxxxxxxxxxxxxxxxxxxxxxxxxxx)

“代码命中”记录器代码永远不会被命中,一段时间后函数就会超时。

有人知道发生了什么事吗?我可以在本地开发环境以及实际的 Azure 上重现该问题。

最佳答案

那里缺少很多指令或程序集引用 除了最后一个 } 是不必要的。

关于c# - Azure Function Post C# 不以大体执行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/70257853/

相关文章:

c# - Lambda 范围说明

c# - List<T> 属性的线程安全访问

python - 使用 Python 托管身份创建 Azure 数据工厂链接服务

azure - 一个可以监听所有容器的 Cosmos DB 更改源的 Azure 函数

typescript - ‘serviceBusTrigger’, 'signalR' 绑定(bind)类型突然未注册

c# - 快速更新 MSSQL 中的列

android - Websocket 服务器作为 Azure 上的服务?

c# - 从 Microsoft.Azure.DocumentDb 迁移到 Microsoft.Azure.Cosmos 以进行数据访问。并非所有选项都可用

azure - 检查是否使用 Powershell 启用了 Azure Function

c# - 使用 LINQ 按 IList 的内容过滤 DbSet