基于 WCF 的 LINQ 服务 (DomainService)

发布于 2024-10-13 09:29:39 字数 1062 浏览 5 评论 0原文

我有一个简单的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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

雨后彩虹 2024-10-20 09:29:40

该异常几乎肯定是由于数据集较大所致,因此您可以尝试增大 <绑定> 中的最大缓冲区/消息大小。配置,例如:

<binding name="MyServiceBinding" maxReceivedMessageSize="6291456" maxBufferSize="6291456">
    <readerQuotas maxArrayLength="6291456" maxStringContentLength="6291456"/>
</binding>

确保将它们添加到客户端服务器配置中的绑定中。

至于获取要在服务器上执行的查询的其他客户端定义部分,您可能需要将返回值设置为 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:

<binding name="MyServiceBinding" maxReceivedMessageSize="6291456" maxBufferSize="6291456">
    <readerQuotas maxArrayLength="6291456" maxStringContentLength="6291456"/>
</binding>

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文