【问题标题】:xamarin form + odataxamarin 形式 + odata
【发布时间】:2015-06-18 11:28:43
【问题描述】:

谁能告诉我如何使用 Simple.Odata.Client 以 xamarin 形式从 OData 服务中检索数据?

我尝试通过以下方式:

在便携式项目中

public App()
{
  GetDocument();
}

public async void GetDocument()
{
     String result = await ODataServiceAgent.GetDocuments(skipCount);
}

在 OData 服务调用中

public static async Task<string> GetDocuments(int skipCount)
        {
            string json = string.Empty;
            try
            {

                var client1 = new ODataClient(new ODataClientSettings(ServiceConstant.sURL_Base, new System.Net.NetworkCredential(ServiceConstant.NCUserName, ServiceConstant.NCPassword))
                {
                    IgnoreResourceNotFoundException = true,
                    //OnTrace = (x, y) => Console.WriteLine(string.Format(x, y)),
                });


                string commands = string.Format(ServiceConstant.sURL_WholeDataByPagging, ServiceConstant.servicePaggingTopCount, skipCount);

                IEnumerable<IDictionary<string, object>> configs = client1.FindEntriesAsync(commands).Result;

                List<IDictionary<string, object>> configList = ((List<IDictionary<string, object>>)configs.ToList());

                json = JsonConvert.SerializeObject(configList);

            }
            catch (Exception ex)
            {
                string excepstionMessage = ex.Message;
            } 
            return json;
        }

当使用“FindEntriesAsync”行进行实际调用时,它没有响应

【问题讨论】:

  • 你需要等待 FindEntriesAsync()

标签: xamarin.forms simple.odata


【解决方案1】:

它在对 Result 的调用中。一般来说,在异步方法上调用 Result 或 Wait 并不是一个好主意:它可能在某些环境(如桌面 Windows)中工作,但在其他环境中会死锁,尤其是在移动环境中。所以只是等待它,不要做 .Result 或 .Wait。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-12-21
    • 2021-10-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多