【问题标题】:OData Connection in Xamarin FormXamarin 形式的 OData 连接
【发布时间】:2014-10-17 04:57:22
【问题描述】:

我的代码崩溃并在模拟器上出现以下错误。它尝试在 GetDataFromOdataService() 方法中运行 try 块并抛出错误并发出警报。我正在使用 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;
        }

【问题讨论】:

  • 您可以通过电子邮件发送您的最新代码吗?
  • 好的,我现在发送。

标签: xamarin odata xamarin.forms


【解决方案1】:

几个问题:-

在构造函数中它正在执行var list = new ListView(),它在本地约束它而不是设置类级别范围变量。因此将其调整为list = new ListView()

另一件事是在GetTheData 函数中,项目源被分配为list.ItemsSource = myList;,需要更改为list.ItemsSource = Customers;

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

【讨论】:

  • @Casillas 我正在使用 MVVMCross 框架构建 Xamarin.ios 应用程序并希望使用 OData 服务。您能否告诉我如何在 Xamarin.iOS 中使用 OData 服务?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2019-07-18
  • 1970-01-01
  • 2014-08-10
  • 1970-01-01
  • 2017-11-25
  • 1970-01-01
  • 2021-10-05
相关资源
最近更新 更多