Click here to Skip to main content
15,900,724 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
API calls gets stalled until one API call is complete. After first call finishes then second call is hit to API. I want by browser to get response from multiple API methods at a time.


jquery code
var UserMasterId = $('#lblHdnUsrMstId').text();
   $.ajax({
       url: '/api/CRMLeftSideBarAPI/getMyCalls',
       type: 'GET',
       data: { UserMasterId: UserMasterId },
       beforeSend: function () {
           $('.ModalAutocomplete').fadeIn('slow');
       },
       complete: function () {
           $('.ModalAutocomplete').fadeOut('slow');
       }
   }).done(function (data) {
      // do something here
   }).error();

var UserMasterId = $('#lblHdnUsrMstId').text();
   $.ajax({
       url: '/api/CRMLeftSideBarAPI/getMyUsers',
       type: 'GET',
       data: { UserMasterId: UserMasterId },
       beforeSend: function () {
           $('.ModalAutocomplete').fadeIn('slow');
       },
       complete: function () {
           $('.ModalAutocomplete').fadeOut('slow');
       }
   }).done(function (data) {
      // do something here
   }).error();


API code

public string getMyCalls(string UserMasterId)
{
  //do something here
}

public string getMyUsers(string UserMasterId)
{
  //do something here
}


i want to get response for both api calls at a time, not one after the other.

What I have tried:

API calls gets stalled until one API call is complete. After first call finishes then second call is hit to API. I want by browser to get response from multiple API methods at a time.

Do i need to write async await for API method?
Posted
Updated 20-Jan-21 21:48pm
Comments
Richard Deeming 20-Jan-21 11:58am    
It depends how you're triggering the AJAX calls, which you haven't shown.

If you have session state enabled on the WebAPI, then your requests may also be queued up waiting for write access to the session. Check your browser's developer tools to see whether the second request is initiated before the first request completes.
Member 15050987 21-Jan-21 0:20am    
Yes I have used session to manage data. All my API calls are initiated before the first request completes. I have so may API calls queued in network. I think its not working due to session state as you mentioned.

Thanks for your reply.

1 solution

With session state enabled on the server, all requests with the same session ID cookie will be queued and processed one at a time. This is because one request may alter the session state, and that change needs to be visible to the next request.

You will need to either eliminate session state from your API, or change it to have read-only access to the session.

The Downsides of ASP.NET Session State - JonoW[^]
When a Single ASP.NET Client makes Concurrent Requests for Writeable Session Variables - Simple Talk[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900