question

diegogutierrez-8074 avatar image
0 Votes"
diegogutierrez-8074 asked lextm commented

Return response before other process

Hi.

I am working with a dot net core web api which calls several web services.

Once the first web service responses I have to return the response inmediately to the caller and the remaining calls must be executed in a background process.

How can I send the response to the caller before other process? When I call the "return command" it returns the response but inmediately stop the process.

Thanks in advance.

dotnet-csharp
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

1 Answer

Viorel-1 avatar image
0 Votes"
Viorel-1 answered lextm commented

Maybe create a Thread or Task and start it explicitly before return command.

What kind of background process are you creating?


· 2
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Hi Viorel.

The background process are just two Url calls.

This is the flow process:

1 - Call the first URL : HttpResponseMessage response = await client.PostAsync(url, new StringContent(jsonRequest, UnicodeEncoding.UTF8, "application/json"));
2 - Return to the client response
3 - Call the second URL in background : HttpResponseMessage response = await client.PostAsync(url, new StringContent(jsonRequest, UnicodeEncoding.UTF8, "application/json"));
4 - Call the third URL in background : HttpResponseMessage response = await client.PostAsync(url, new StringContent(jsonRequest, UnicodeEncoding.UTF8, "application/json"));

I need to call the first Url and return the message to the client. After that call second and third url in background.

0 Votes 0 ·
lextm avatar image lextm diegogutierrez-8074 ·

Examples can be found in articles like this

1 Vote 1 ·