任何人都可以告诉我如何使用带有xamarin表单的Simple.Odata.Client从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”行进行实际调用但没有响应
答案 0 :(得分:0)
在对Result的调用中。一般来说,在异步方法上调用Result或Wait不是一个好主意:可能在某些环境(如桌面Windows)中工作,但它会在其他环境中死锁,尤其是移动设备。所以等待它,不要做.Result或.Wait。