I'm using async methods in my WebAPi controllers:
public async Task<HttpResponseMessage> SampleMethod(int subscriptionNumber, DateTime departureDate)
{
// [...]
}
How do I configure the request timeout? The operation can take up to a couple of minutes and I have to make sure that the request do not timeout.
In MVC there is an attribute called [AsyncTimeout]
. Are there an equivalent in WebApi? Can it be configured globally?
Timeouts happen if a service takes more than 30 seconds to respond to a call. If a timeout occurs, you'll see the 500 error status code with details about the timeout in the response. Timeouts are typically caused by one of two things: The call involves too much data. There is a network/service issue.
Quick snippet of code: HttpWebRequest webReq = (HttpWebRequest)HttpWebRequest. Create(url); webReq. Timeout = 5000; HttpWebResponse response = (HttpWebResponse)webReq.
Good question, I would recommend to handle this from client side - you can always specify timeout settings in your consumer code, even if it is ajax:
$.ajax({
url: "/ajax_json_echo/",
timeout: 1000,
...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With