Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/url/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# HttpClient.PostAsync在不执行的情况下继续_C#_Asynchronous_Httpclient_Azure Functions_Azure Logic Apps - Fatal编程技术网

C# HttpClient.PostAsync在不执行的情况下继续

C# HttpClient.PostAsync在不执行的情况下继续,c#,asynchronous,httpclient,azure-functions,azure-logic-apps,C#,Asynchronous,Httpclient,Azure Functions,Azure Logic Apps,我需要一些帮助来弄清楚为什么continueWith块中的以下代码没有为长时间运行的服务调用执行 public static async void postServiceAsync(string json, string postServiceUrl, string callbackUrl, string clientId, string tenant, string secret,

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

     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多分钟,也会返回一个值。我没有使用Wait,因为我希望在调用PostAsync后继续执行。我只希望在长时间运行的服务执行完成后执行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函数中,我需要立即返回已接受的状态代码。使用PostAsync调用完长时间运行的服务后,我需要发布到回调URL,这就是我在continueWith块中所做的。正如我提到的,如果服务运行时很短,它就可以工作。我尝试了Camilo关于添加wait的建议,但是continueWith代码没有得到执行。我还尝试摆脱continueWith,只是在等待客户端后添加了代码。PostAsync

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

如果方法是异步的,为什么要使用ContinueWith?这完全没有道理。等待PostAsync的呼叫,然后与callHi Camilo一起完成您的后续工作。我尝试添加wait,但没有成功。我在上面的帖子中添加了更多的背景信息。