基于 WCF 的 LINQ 服务 (DomainService)
我有一个简单的DomainService:
[EnableClientAccess]
public class DomainService1 : IDomainService1
{
[Query(IsComposable = true)]
public IEnumerable<int> GetCollection(int from, int count)
{
const int max = 100000;
int[] _collection;
_collection = new int[max];
for (int i = 0; i < max; i++)
{
_collection[i] = i;
}
return _collection.Skip(from).Take(count);
}
}
在客户端我生成了代理:客户端
我需要在客户端编写LINQ查询并在服务器端执行它并通过服务返回查询结果。
当我这样做时:
var res1 = client.GetCollection(100, 20).Skip(5).Take(5);
比 client.GetCollection(100, 20) 在服务器端执行并 Skip(5) 和 Take(5) 在客户端。
当我这样做时:
var res2 = client.GetCollection(100, 90000).Skip(10).Take(10);
它抛出异常:
底层连接已关闭:连接意外关闭。
我认为这是由于 client.GetCollection(100, 90000) 返回大结果集。
有没有办法更好地了解服务器故障的原因? 是否可以从客户端在服务器上执行查询?我想是的,因为这允许 LinqToEntitiesDomainService。但我不能使用 EF,因为我只能访问内存中存储的对象列表。
谢谢。
日本邮政
I have a simple DomainService:
[EnableClientAccess]
public class DomainService1 : IDomainService1
{
[Query(IsComposable = true)]
public IEnumerable<int> GetCollection(int from, int count)
{
const int max = 100000;
int[] _collection;
_collection = new int[max];
for (int i = 0; i < max; i++)
{
_collection[i] = i;
}
return _collection.Skip(from).Take(count);
}
}
On client side I have generated proxy: client
I need comose LINQ query on client side and perform it on server side and throught service return query result.
When I do:
var res1 = client.GetCollection(100, 20).Skip(5).Take(5);
than client.GetCollection(100, 20) in performed on server side and Skip(5) and Take(5)
on client side.
When i do:
var res2 = client.GetCollection(100, 90000).Skip(10).Take(10);
it throw exception:
The underlying connection was closed: The connection was closed unexpectedly.
I think that this is due, that client.GetCollection(100, 90000) return large resultset.
Is a way get better information about reason why server fault?
And it possible perform query from client on server? I think so, because this allows LinqToEntitiesDomainService. But i cannot use EF, because i have access only to list of object stroed in memory.
Thank you.
JPo
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
该异常几乎肯定是由于数据集较大所致,因此您可以尝试增大 <绑定> 中的最大缓冲区/消息大小。配置,例如:
确保将它们添加到客户端和服务器配置中的绑定中。
至于获取要在服务器上执行的查询的其他客户端定义部分,您可能需要将返回值设置为 IQueryable。反而。
The exception is almost certainly due to the large dataset, so you can try upping the maximum buffer/message sizes in the <binding> config, eg:
Make sure you add those to the bindings in both the client and the server's config.
As for getting the additional client-defined parts of the query to execute on the server, you might need to make the return value an IQueryable<int> instead.