Xamarin形式的OData连接
我的代码在模拟器上崩溃并出现以下错误。它尝试在getDataFromOdatService()方法中运行try块,抛出错误并发出警报。我正在使用Xamarin.FormXamarin形式的OData连接,xamarin,odata,xamarin.forms,Xamarin,Odata,Xamarin.forms,我的代码在模拟器上崩溃并出现以下错误。它尝试在getDataFromOdatService()方法中运行try块,抛出错误并发出警报。我正在使用Xamarin.Form using Simple.OData.Client; using System.Threading.Tasks; private ODataClient mODataClient; protected async override void OnAppearing () { base
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;
}
使用Simple.OData.Client;
使用System.Threading.Tasks;
私有ODataClient mODataClient;
出现()时受保护的异步重写无效
{
base.OnAppearing();
等待初始化的taservice();
等待GetDataFromOdataService();
}
公共异步任务InitializeDataService(){
试一试{
mODataClient=新的ODataClient(“http://services.odata.org/Northwind/Northwind.svc/");
}
抓住{
等待显示警报(“错误”、“连接错误”、“确定”、“取消”);
System.Diagnostics.Debug.WriteLine(“错误!”);
}
返回true;
}
公共异步任务GetDataFromOdataService(){
试一试{
myCustomers=wait mODataClient.For(“客户”).Top(10.FindEntriesAsync();
}
抓住{
等待显示警报(“错误”、“连接错误”、“确定”、“取消”);
System.Diagnostics.Debug.WriteLine(“错误!”);
}
返回true;
}
夫妻问题:-
在构造函数中,它正在执行var list=new ListView()
,这比设置类级范围变量更能在本地约束它。因此,这被调整为list=new ListView()
另一件事是在gethedata
函数中,其中项源被指定为list.ItemsSource=myList代码>需要更改为list.ItemsSource=Customers的位置代码>
我已经重新打包了zip文件并发送给你。让我知道这对你有用吗?您现在应该可以在列表视图中看到您的所有客户了您可以通过电子邮件发送您的最新代码吗?当然,我现在就发送。@Casillas我正在使用MVVMCross框架构建Xamarin.ios应用程序,并希望使用OData服务。您能告诉我如何使用Xamarin.iOS中的OData服务吗?