There are three layers in ASP.NET MVC application. From first layer, I am calling a method in second layer and the method calls in third layer where I call web service. Below is the code. Both the layers (2 and 3) are added as Class Library
in the solution.
namespace Web.Controllers // Layer 1
{
using Web.Services;
// other usings...
public class Controller1
{
[HttpPost]
public JsonResult Search(SomeObject request)
{
Service service = new Service();
var result = service.Search(request).Result;
}
}
}
namespace Web.Service // Layer 2
{
using Web.Library;
// other usings...
public class Service
{
public async Task<SomeType> SearchFlights(SomeObject requestModel)
{
SomeObjectReturn result = new SomeObjectReturn();
Library library = new Library();
var result = await library.Search(requestModel);
return result;
}
}
}
namespace Web.Library // Layer 3
{
public class Library
{
public async Task<SomeObjectReturn> Search(SomeObject request)
{
// here I call Sabre service to get the result...
SomeObjectReturn obj = new SomeObjectReturn();
RestClient restClient = RestClientFactory.Create();
IActivity activity = new InstaFlightsActivity(restClient, requestModel);
Sabre.Library.Workflow.Workflow workflow = new Sabre.Library.Workflow.Workflow(activity);
SharedContext sharedContext = await workflow.RunAsync();
// map sharedContext to SomeObjectReturn
return obj;
}
}
}
Now I don't know why there is deadlock on await workflow.RunAsync
. I have also tried .ConfigureAwait(false)
on workflow.RunAsync
. But the deadlock is being generated anyway. I don't know what's wrong with the code.
BTW, I have made changes as below in Controller
and i got the result.
public async Task<JsonResult> Search(SomeObject request) {...
instead of above.