2014-10-16 55 views
3

我的代码崩溃并在模拟器上出现以下错误。它尝试运行GetDataFromOdataService()方法中的try块,并引发错误并发出警报。我使用Xamarin.FormXamarin形式的OData连接

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; 
     } 

enter image description here

+0

你能通过电子邮件发送你的最新代码吗? – Pete 2014-10-16 19:33:24

+0

当然,我现在发送它。 – casillas 2014-10-16 19:33:41

回答

1

夫妇的问题: -

在它是做var list = new ListView()构造制约了它不是设置类级别范围变量本地。因此调整为list = new ListView()

另一件事是在GetTheData函数中,其中项源被指定为list.ItemsSource = myList;,它需要更改为list.ItemsSource = Customers;

我已经将zip文件重新打包并发送给你。让我知道这是否适合你?您现在应该可以在ListView中看到您的所有客户。

+0

@Casillas我正在使用MVVMCross框架构建Xamarin.ios应用程序,并且想要使用OData服务。你能否给我这个想法如何使用Xamarin.iOS中的OData服务? – 2017-11-18 08:45:57