0

I've seen a solution like this in a few different places on the web, and it look to be ideal for what I need to do (I'd like to set up a RabbitMQ durable queue for this, but my bosses need a solution now).

I'm using the pattern of adding a this in my .NET Core 3.1 controller in this (for some reason) SOAP API:

Response.OnCompleted(async () => 
{
    await thisOtherThingIWantToDoAfterISendTheResponse(params).ConfigureAwait(false);
});

I've tried this inside a try / finally strategy and I've tried it just attaching the Response.OnCompleted somewhere before the return statement. What happens every time is the Status Code is returned very quickly in about the amount of time I expect (verified in Postman randomly assigning different status codes to the Microsoft.AspNetCore.Mvc.JsonResult object), but the response body does not appear until the OnCompleted call occurs.

I thought perhaps this was because this is a Json object that is passed into (and then manipulated in) the OnCompleted async work (thisOtherThingIWantToDoAfterISendTheResponse), so I tried serializing the object into a string primitive and returning that string while passing the object to the subsequent async method, but got the same result, just with a string response body this time after the subsequent task completed.

It's a bit frustrating that the method knows what to send (in that it doesn't change due to the async call), and it can send the response (as evidenced by the response code showing up immediately), it just won't do what clearly is intended with these commands. How can I solve this?

halfer
  • 19,471
  • 17
  • 87
  • 173

0 Answers0