[英]How to asynchronously consume a WCF Data Service using paging with BeginExecute in UWP
I have a WCF Data Services service and its methods return Queryable lists. 我有WCF数据服务服务,其方法返回Queryable列表。
Using a Java library, I could consume it with client-side paging (using top
and take
). 使用Java库,我可以在客户端分页中使用它(使用
top
和take
)。
Now I intend to consume it with an UWP application. 现在,我打算通过UWP应用程序使用它。
Unfortunately the following code does not work: 不幸的是,以下代码不起作用:
var result = client.CreateQuery<Information>("GetInformation")
.AddQueryOption("id", string.Format("'{0}'", actualId))
.Skip(index)
.Take(amount).ToList();
I get this exception: 我得到这个例外:
This target framework does not enable you to directly enumerate over a data service query.
此目标框架使您无法直接枚举数据服务查询。 This is because enumeration automatically sends a synchronous request to the data service.
这是因为枚举自动将同步请求发送到数据服务。 Because this framework only supports asynchronous operations, you must instead call the BeginExecute and EndExecute methods to obtain a query result that supports enumeration.
因为此框架仅支持异步操作,所以必须改为调用BeginExecute和EndExecute方法以获得支持枚举的查询结果。
As I had to use BeginExecute
, I can no longer use Skip
and Take
. 由于必须使用
BeginExecute
,因此不能再使用Skip
and Take
。
var query = client.CreateQuery<Information>("GetInformation")
.AddQueryOption("id", string.Format("'{0}'", actualId));
query.BeginExecute((x) =>
{
var result= query.EndExecute(x);
foreach (var information in result)
{
};
}, null);
How should I do it with this asynchronous method? 我应该如何使用这种异步方法呢?
I was having the same problem but with OData. 我在使用OData时遇到了同样的问题。 I found the solution in the next blog http://jqyblogger.blogspot.com/2013/11/linq-query-error-message-on-windows.html and basically we need to use the asyncronus tools for OData.
我在下一个博客http://jqyblogger.blogspot.com/2013/11/linq-query-error-message-on-windows.html中找到了解决方案,基本上,我们需要对OData使用asyncronus工具。
Default.Container context = new Default.Container(new Uri("url_to_OData_Service"));
var nquery = context.Reports
.Where(r => r.ReportId == 1)
.Select(p => p);
DataServiceQuery<Report> query = (DataServiceQuery<Report>)nquery;
TaskFactory<IEnumerable<Report>> taskFactory = new TaskFactory<IEnumerable<Report>>();
IEnumerable<Report> result = await taskFactory.FromAsync(query.BeginExecute(null, null), iar => query.EndExecute(iar));
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.