I'm consuming API form the async
method and my code as follows,
public async void Test(string token, int tenantId, string fromDate,string searchText)
{
try
{
string serviceUrl = "http://localhost/Testapi/api/details/requestDetails/Details";
string jsonParamterData = new JavaScriptSerializer().Serialize(new
{
FromDate = fromDate,
SearchText = searchText,
});
HttpClient client = new HttpClient();
HttpMethod method = new HttpMethod("POST");
HttpRequestMessage message = new HttpRequestMessage(method, serviceUrl);
StringContent content = new StringContent(jsonParamterData, Encoding.UTF8, "application/json");
client.DefaultRequestHeaders.Add("TenantId", tenantId.ToString());
client.DefaultRequestHeaders.Add("Authorization", string.Format("bearer {0}", token));
message.Content = content;
var response = await client.PostAsync(serviceUrl, content);
var result = await response.Content.ReadAsStringAsync();
client.Dispose();
}
}
I need to get that response result from another method.
public string GetValue(){
}
But Test()
method is void, So how can I access Test()
result value from another method? IS it possible to return value inside async
methods.
Updated:
[WebMethod(EnableSession = true)]
public string GetValue(){
}
But GetValue()
is a web method