1

谁能告诉我如何使用 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”行发生的,但它没有响应

4

1 回答 1

0

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

于 2015-06-20T12:13:28.910 回答