OData connection in Xamarin form
My code crashes and gives the following error on the simulator. It tries to run a try block in the GetDataFromOdataService () method and throws an error and also throws a warning. I am using Xamarin.Form
using Simple.OData.Client;
using System.Threading.Tasks;
private ODataClient mODataClient;
protected async override void OnAppearing ()
{
base.OnAppearing ();
await InitializeDataService ();
await GetDataFromOdataService();
}
public async Task <bool> InitializeDataService(){
try {
mODataClient = new ODataClient ("http://services.odata.org/Northwind/Northwind.svc/");
}
catch {
await DisplayAlert("Error", "Connection Error", "OK", "Cancel");
System.Diagnostics.Debug.WriteLine("ERROR!");
}
return true;
}
public async Task<bool> GetDataFromOdataService (){
try {
myCustomers= await mODataClient.For("Customers").Top(10).FindEntriesAsync();
}
catch {
await DisplayAlert("Error", "Connection Error", "OK", "Cancel");
System.Diagnostics.Debug.WriteLine("ERROR!");
}
return true;
}
source to share
A couple of questions: -
In the constructor, it was doing var list = new ListView()
that limited it locally than setting a class level scope variable. Therefore, he was tuned in list = new ListView()
.
Another thing was in the function GetTheData
where the source of the elements was assigned as list.ItemsSource = myList;
, where it needed to be changed to list.ItemsSource = Customers;
.
I repackaged the zip file and sent it to you. Let me know if this works for you? You should now see all of your clients in the ListView .
source to share