For the customer to know how long it will take, you need to send an answer. This type of problem can be adequately addressed using an asynchronous approach. There are advantages to doing this. For example, in case of high demand, you can queue requests to your DW and not leave "locked" threads on your server. In addition, customers do not need to change connection timeouts to their REST service. Certainly the complexity of implementation increases a little, but it is worth you have a more elegant and scalable solution.
My suggestion is that you create a service POST /QtdeVendasNoPeriodo/{dtInicio}/{dtFim}
. Upon receiving the request, you submit the report generation to a thread worker and immediately respond to the client with HTTP code 202 Accepted
and the HTTP header Location
with the address where the report generation status will be consulted.
The response to service POST
would be something like:
HTTP/1.1 202 Accepted
Location: https://<seu_endereco_web>/filaProcessamento/sdf4524wrwerwe
sdf4524wrwerwe
is any identifier that uniquely informs the status of the report generation. /filaProcessamento/{idStatusProcessamento}
is a service GET
where you would answer, for example:
http GET https://<seu_endereco_web>/filaProcessamento/sdf4524wrwerwe
HTTP/1.1 200 Ok
<resposta>
<status>PENDENTE</status>
<tempoRestante>120 segundos</tempoRestante>
<link rel="cancel" method="delete" href="/filaProcessamento/sdf4524wrwerwe" />
</resposta>
I used XML above, but it might be JSON. The tag link
would be to inform the user the possibility to cancel the generation of the report. In this case, a service DELETE
it would be necessary.
Once the report has been created, the GET response described above would be
http GET https://<seu_endereco_web>/filaProcessamento/sdf4524wrwerwe
HTTP/1.1 303 See Other
Location: https://<seu_endereco_web>/QtdeVendasNoPeriodo/97525252665
The HTTP code 303
is for client redirection. The header Location
tells the customer where the feature is available. It is necessary that you implement a service GET /QtdeVendasNoPeriodo/{idResultado}
, where idResultado
is an identifier any of the report expected by the client, which will also be controlled by its application.
Some implementation details need to be decided according to your need. For example, in response to service GET /QtdeVendasNoPeriodo/{idResultado}
, inform in the header Expires
the time the report can be cached. Enter consistent HTTP codes such as 404 Not Found
, if the report does not exist, or 410 Gone
after the customer has already downloaded the report or its application has discarded the data after a certain period of time. Finally, several improvements can be considered.
Safety tip: the idResultado
can be, for example, a large random number or a hash. Thus, an average customer has a low probability of being able to access other customers' results through service queries GET /QtdeVendasNoPeriodo/{idResultado}
. If you use a sequence, for example, a customer may have access to other results only by increasing idResultado
.
What does DW mean?
– NilsonUehara
porem o client nao espera
what is this client ? is a screen ? another application ? the most important thing is you tell which client is this kkk– Erick Maia
is an application, an application that will receive from this web service a json more or less in this format { January: 10, February: 1000, March: 6000000, . . December: 525 }
– user2913044
DW stands for Data Warehouse
– user2913044
It seems your question is duplicated here https://answall.com/questions/214371/webmetodo-timeout-exception?rq=1
– Rodrigo Nogueira