HttpClient.PostAsync continueWith 未执行

HttpClient.PostAsync continueWith not executing

我需要一些帮助来弄清楚为什么 continueWith 块中的以下代码在长时间的 运行ning 服务调用中没有被执行。

     public static async void postServiceAsync(string json, string postServiceUrl, string callbackUrl, string clientId, 
                                                  string tenant, string secret, string d365Environment, TraceWriter log)
        {
            HttpClient client = new HttpClient();

            //Get authorization header
            string authHeader = await D365Authorization.getAccessToken(clientId, tenant, secret, d365Environment);
            client.DefaultRequestHeaders.Add("Authorization", authHeader);
            var httpContent = new StringContent(json);

            client.Timeout = TimeSpan.FromMinutes(90);
            client.PostAsync(postServiceUrl, httpContent).ContinueWith(async (result) =>
            {
               //call callback URL
               //This is not executed after a long running service that runs for 20 minutes.
             }
         }

如果服务执行时间很短,continueWith 代码会得到 运行。我认为这是一个超时问题,所以我添加了 client.Timeout 值。我尝试在 Postman 中调用该服务,即使等待 20 多分钟后,一个值仍为 returned。我没有使用 await,因为我希望在调用 PostAsync 后继续执行。我只想在长时间的 运行ning 服务执行完成后执行 continueWith 回调。感谢您的帮助!

上面称为 postServiceAsync 的方法是从 Azure 函数调用的,该函数是从 Azure 逻辑应用程序 http webhook 操作调用的。这是 Azure 函数:

public static async Task<HttpResponseMessage> Run([HttpTrigger(AuthorizationLevel.Function, "post", Route = null)]HttpRequestMessage req, TraceWriter log)
        {
            ...

            PostServiceAsync.postServiceAsync(json, shipServiceUrl, callbackUrl, clientId, tenant, secret, d365Environment, log);

            var resp = req.CreateResponse(HttpStatusCode.Accepted);
            return resp;
        }
    }

在 Azure 函数中,我需要立即 return 已接受状态代码。在我使用 PostAsync 完成调用长 运行ning 服务后,我需要 post 到回调 URL,这就是我在 continueWith 块中所做的。就像我提到的,如果服务 运行time 很短,它就可以工作。我尝试了 Camilo 关于添加 await 的建议,但 continueWith 代码没有得到执行。我还尝试去掉 continueWith 并在 "await client.PostAsync(...)" 之后添加代码。

事实证明,对于没有响应的 http 调用,Azure 函数存在 230 秒超时。我可能无法将 Azure 函数用于我的目的。