I have created an api to get data but it is showing timeout error. I am calling the function inside main function of Xamarin that is called when app is run.
public MainPage()
{
InitializeComponent();
//this.BindingContext = new PatientViewModel();
Task<PatientModel> abc = GetPatientData();
}
my function for api GetAsync call:
public async Task<PatientModel> GetPatientData()
{
PatientModel patient = null;
try
{
Uri weburl = new Uri("myuri");
HttpClient client = new HttpClient();
Console.WriteLine("a");
HttpResponseMessage response = await client.GetAsync(weburl);
Console.WriteLine("b");
if (response.IsSuccessStatusCode)
{
Console.WriteLine("in");
patient = await response.Content.ReadAsAsync<PatientModel>();
Console.WriteLine("in funciton");
return patient;
}
return patient;
}catch(Exception ex)
{
Console.WriteLine(ex);
return patient;
}
}
}
Code is not showing any error. When execution went to GetAsync statement it waits for a while and exception occurs.
System.Net.WebException: The request timed out. ---> Foundation.NSErrorException: Exception of type 'Foundation.NSErrorException' was thrown.
Task<PatientModel> abcafter the constructor?