我正在使用指向OData端点的WCF数据服务。如果使用DataServiceQuery,则可以毫无问题地管理连续性。
var collection = new DataServiceCollection<T>();
collection.LoadCompleted += (sender, e) =>
{
if (e.Error != null)
{
callback(null, e.Error);
return;
}
var thisCollection = (DataServiceCollection<T>) sender;
if (thisCollection.Continuation != null)
{
thisCollection.LoadNextPartialSetAsync();
}
else
{
var items = thisCollection.ToList();
callback(items, e.Error);
}
};
collection.LoadAsync(query);
但是,我看不到如何为DataServiceContext.BeginExecute(string url,...)方法执行相同的操作。
_odataContext.BeginExecute<T>(new Uri(requestUrl), x =>
{
var items = _odataContext.EndExecute<T>(x);
//not sure how to get the rest of the items with this method
});
如何使用基于url的查询方法,但仍获得延续支持?
最佳答案
同步样本(为了简化起见):
var r = ctx.Execute<Product>(new Uri("http://services.odata.org/Northwind/Northwind.svc/Products"));
QueryOperationResponse<Product> response = (QueryOperationResponse<Product>)r;
response.Count();
Console.WriteLine(response.GetContinuation());
简而言之,Execute方法返回QueryOperationResponse的实例,该实例实现IEnumerable但也公开了延续。
关于.net - 如何使用URL查询处理WCF-OData中的延续?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5515829/