Reputation: 307
Below is the way i am currently calling the web service to project,
public JsonResult CruiseBE_Data1(string cruise)
{
CruiseService GetPorts = new CruiseService();
projectCruise.CruiseServiceASD.ServiceAuthHeader serviceAuthHeaderValue_Cruise = new projectCruise.CruiseServiceASD.ServiceAuthHeader();
serviceAuthHeaderValue_Cruise.username = "xxxxxxxxxx";
serviceAuthHeaderValue_Cruise.password = "xxxxxxxxxx";
GetPorts.ServiceAuthHeaderValue = serviceAuthHeaderValue_Cruise;
string CruisePorts = "";
CruisePorts = GetPorts.GetPorts();
return Json(CruisePorts);
}
What I am trying to do is i want to change above to async way of requesting can any one please guide me how to do that.
Upvotes: 0
Views: 41
Reputation: 286
The easiest way would be to wrap your GetPorts.GetPorts()
call in a Task.Run()
:
CruisePorts = await Task.Run(() => GetPorts.GetPorts());
But take care, that your method then must be defined as
public async Task<JsonResult> CruiseBE_Data1(string cruise)
Upvotes: 1