Hi,
i have wrote a small code snippet to fetch the data from WCF service and to display it in list view. everything seems fine but the API call is not waiting for the service to return the data (service will return the data in LIST). Here is my code and please suggest me this.
Expecting:
List workHours = UserWorkingHours(Service_WCF.EntryOperation.Fetch);
if(workHours == null)
return;
Existing: (calling this function is not waiting for the service to return with data)
UserWorkingHours(Service_WCF.EntryOperation.Fetch);
/// WCF Service
public void UserWorkingHours(Service_WCF.EntryOperation entryOperation)
{
EndpointAddress _endPoint = new EndpointAddress("http://172.22.0.187:62720/Service1.svc");
BasicHttpBinding _binding = new BasicHttpBinding
{
Name = "basicHttpBinding",
MaxBufferSize = 2147483647,
MaxReceivedMessageSize = 2147483647
};
Service_WCF.Service1Client _service = new Service_WCF.Service1Client(_binding, _endPoint);
Service_WCF.WorkingHoursRequest _WorkingHoursRequest = new Service_WCF.WorkingHoursRequest()
{
EntryOperation = entryOperation,
};
_service.UserWorkingHoursCompleted += _service_UserWorkingHoursCompleted;
_service.UserWorkingHoursAsync(_WorkingHoursRequest);
}
void _service_UserWorkingHoursCompleted(object sender, Service_WCF.UserWorkingHoursCompletedEventArgs e)
{
List<Service_WCF.WorkingHours> _workingHours = new List<Service_WCF.WorkingHours>();
Device.BeginInvokeOnMainThread(async () =>
{
string error = string.Empty;
if (e.Error != null)
error = e.Error.Message;
else if (e.Cancelled)
error = "Cancelled";
if (!string.IsNullOrEmpty(error))
{
await DisplayAlert("Kresoft", error, "OK");
return;
}
if (e.Result.status.Equals(false) || e.Result.workingHours == null)
{
_workingHours = null;
return;
}
});
_workingHours = e.Result.workingHours.ToList();
}