Saad
Saad

Reputation: 366

How to increase executionTimeout

i have two application .net web api (version 4.7.1)
the first app call some api from second app
i want to increase timeout to 5 min
i add executionTimeout to the first app, but dosn't work this is the web config of my first app :

 <system.web>
    <compilation debug="false" targetFramework="4.7.1" />
    <httpRuntime targetFramework="4.7.1" executionTimeout="300" />
  </system.web>

i test just with 2 sec
i don't know why dosn't work !

x x x x x x x x x x x x x x x

how i call the socond app :

public async System.Threading.Tasks.Task<TestResponseOfAccountViewModel> GetAllAccountsAsync(string pClientId, System.Threading.CancellationToken cancellationToken)
        {
            var urlBuilder_ = new System.Text.StringBuilder();
            urlBuilder_.Append(BaseUrl != null ? BaseUrl.TrimEnd('/') : "").Append("/api/Account/GetAllAccounts");

            var client_ = await CreateHttpClientAsync(cancellationToken).ConfigureAwait(false);
            try
            {
                using (var request_ = new System.Net.Http.HttpRequestMessage())
                {
                    var content_ = new System.Net.Http.StringContent(Newtonsoft.Json.JsonConvert.SerializeObject(pClientId, _settings.Value));
                    content_.Headers.ContentType = System.Net.Http.Headers.MediaTypeHeaderValue.Parse("application/json");
                    request_.Content = content_;
                    request_.Method = new System.Net.Http.HttpMethod("POST");
                    request_.Headers.Accept.Add(System.Net.Http.Headers.MediaTypeWithQualityHeaderValue.Parse("application/json"));

                    PrepareRequest(client_, request_, urlBuilder_);
                    var url_ = urlBuilder_.ToString();
                    request_.RequestUri = new System.Uri(url_, System.UriKind.RelativeOrAbsolute);
                    PrepareRequest(client_, request_, url_);

                    var response_ = await client_.SendAsync(request_, System.Net.Http.HttpCompletionOption.ResponseHeadersRead, cancellationToken).ConfigureAwait(false);
                    try
                    {
                        var headers_ = System.Linq.Enumerable.ToDictionary(response_.Headers, h_ => h_.Key, h_ => h_.Value);
                        if (response_.Content != null && response_.Content.Headers != null)
                        {
                            foreach (var item_ in response_.Content.Headers)
                                headers_[item_.Key] = item_.Value;
                        }

                        ProcessResponse(client_, response_);

                        var status_ = ((int)response_.StatusCode).ToString();
                        if (status_ == "200")
                        {
                            var objectResponse_ = await ReadObjectResponseAsync<TestResponseOfAccountViewModel>(response_, headers_).ConfigureAwait(false);
                            return objectResponse_.Object;
                        }
                        else
                        if (status_ != "200" && status_ != "204")
                        {
                            var responseData_ = response_.Content == null ? null : await response_.Content.ReadAsStringAsync().ConfigureAwait(false);
                            throw new EngineException("The HTTP status code of the response was not expected (" + (int)response_.StatusCode + ").", (int)response_.StatusCode, responseData_, headers_, null);
                        }

                        return default(TestResponseOfAccountViewModel);
                    }
                    finally
                    {
                        if (response_ != null)
                            response_.Dispose();
                    }
                }
            }
            finally
            {
                if (client_ != null)
                    client_.Dispose();
            }
        }

Upvotes: 0

Views: 1129

Answers (1)

Hany Habib
Hany Habib

Reputation: 1405

There is multiple timeouts you have set one of them in the web.config but there is also another timeout to be set when you make HTTP Requests / Connections to DB for example. In your case you need to set the timeout in the HttpClient returned from CreateHttpClientAsync for example :

client.Timeout = TimeSpan.FromSeconds(seconds)

to increase the timeout in the second app call

Upvotes: 1

Related Questions