I am using a WebApi rest service controller, hosted by IIS 7.5, as i understood from this post:
Are all the web requests executed in parallel and handled asynchrono
Do you try async Task ? Here is sample Controller:
public class SendJobController : ApiController
{
public async Task<ResponseEntity<SendJobResponse>> Post([FromBody] SendJobRequest request)
{
return await PostAsync(request);
}
private async Task<ResponseEntity<SendJobResponse>> PostAsync(SendJobRequest request)
{
Task<ResponseEntity<SendJobResponse>> t = new Task<ResponseEntity<SendJobResponse>>(() =>
{
ResponseEntity<SendJobResponse> _response = new ResponseEntity<SendJobResponse>();
try
{
//
// some long process
//
_response.responseStatus = "OK";
_response.responseMessage = "Success";
_response.responseObject = new SendJobResponse() { JobId = 1 };
}
catch (Exception ex)
{
_response.responseStatus = "ERROR";
_response.responseMessage = ex.Message;
}
return _response;
});
t.Start();
return await t;
}
}
Actually, disabling session state is the normal solution for web APIs. If you need it for some/all of your calls, you can call HttpContext.SetSessionStateBehavior (e.g., from Application_BeginRequest
). Multiple read-only session state requests can run concurrently.