Quantcast
Channel: Web API
Viewing all articles
Browse latest Browse all 4850

Bad request (400) response on debug after lot of calls

$
0
0

Hi there!

I'm developing a Web API and I detected a weird behaivour after lot of invokes to a Web API.

The Web API respond normally but after a lot of invocations it start to respond with a "Bad Request" error.

I put a counter and after 23.100 calls the Web API start to respond with a "400 Bad Request" error code. Those calls aren't concurrent, the client invoke the Web API on a foreach loop and wait the response to launch the next.

I'm using IIS Express and VS2013

The code to reproduce the error:

Server:

        [HttpPost]

        [AllowAnonymous]

        [ActionName("GetData")]

        publicint GetData([FromBody] DataEntity param) // DataEntity is a complex type with some arrays, string a some stuff

        {

            return 0;

        }

Client:

           HttpClient httpClient = new HttpClient();

           httpClient.BaseAddress = newUri(serverUrl);

           foreach (DataEntity dataEntity in dataEntityArray)

           {

                httpClient.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));

                HttpResponseMessage res = httpClient.PostAsJsonAsync("/api/EnvioDatosAPI/GetData", dataEntity).Result;

                if (!res.IsSuccessStatusCode)

                {

                    return false; // <--------------    After lot of calls the response is 400. Bad Response

                }

                int retCode = res.Content.ReadAsAsync<int>().Result;

                if (retCode != 0)

                {

                    returnfalse;

                }

            }

My questions:

How can avoid on debug mode appears the "400 Bad response" after lot of calls?

I didn't test the Web API on a IIS (only debugging o a IIS Express) (and I think the aswer is 'No' but only to be certain). Has the same limitation about the numbers of calls a Web API can get on a IIS on a production environment?

Thanks in advance,

Jose I. Merino


Viewing all articles
Browse latest Browse all 4850

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>