更改 DataServiceContext 中的最大消息大小

发布于 2024-11-02 07:15:48 字数 717 浏览 3 评论 0原文

我正在使用 DataServiceContext 从托管 dbml 的 wcf 服务获取数据。一般情况下它工作正常,但返回大量数据(例如二进制文件)的查询会产生常见的 WCF 错误:

The maximum message size quota for incoming messages (65536) has been exceeded. To increase the quota, use the MaxReceivedMessageSize property on the appropriate binding 

问题是我找不到如何更改通道的消息大小。

这是我用来初始化该类的代码:

var channel = new RPDataModelDataContext(DataServiceBaseAddress);
channel.Credentials = CredentialCache.DefaultCredentials;

其中 RPDataModelDataContext 是使用实体框架生成的客户端代理类

public partial class RPDataModelDataContext : 
    global::System.Data.Services.Client.DataServiceContext
{
    // ...

任何人都可以指出我正确的方向吗?

I am using DataServiceContext to get data from a wcf service which is hosting a dbml. It works fine in general but queries that return large amounts of data (e.g. binary files) create the usual WCF error:

The maximum message size quota for incoming messages (65536) has been exceeded. To increase the quota, use the MaxReceivedMessageSize property on the appropriate binding 

The problem is I cannot find how to change the message size of the channel.

Here's the code I use to initialise the class:

var channel = new RPDataModelDataContext(DataServiceBaseAddress);
channel.Credentials = CredentialCache.DefaultCredentials;

where RPDataModelDataContext is a client proxy class generated with the entityframework

public partial class RPDataModelDataContext : 
    global::System.Data.Services.Client.DataServiceContext
{
    // ...

Can anyone point me to the right direction?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(3

楠木可依 2024-11-09 07:15:48

我在这方面也遇到了很多问题。我遗漏了三个细节。

  1. 您必须准确指定服务名称。这应该是完全限定的服务名称。 (即Namespace.ClassName
  2. 您必须提供端点的确切地址。 (见下面的代码)

    <前><代码><服务>;

    <服务名称=“YourDomainNameHere.YourClassNameHere”>

    <端点地址=“http://localhost:19766/YourServiceName.svc”绑定=“webHttpBinding”绑定配置=“higherMessageSize”合同=“System.Data.Services.IRequestHandler”>


  3. 必须指定 maxReceivedMessageSizemaxBufferSize

    <前><代码><绑定>;


    <绑定名称=“higherMessageSize”maxReceivedMessageSize=“2048000”maxBufferSize=“2048000”/>

I was having tons of problems with this one as well. There were three details I was missing.

  1. You MUST specify the service name exactly. This should be the fully qualified service name. (ie. Namespace.ClassName)
  2. You MUST provide the EXACT address of the endpoint. (See code below)

    <services>
        <!-- The service name below has to be the EXACT Namespace.ClassName of your WCF Data Service-->
        <service name="YourDomainNameHere.YourClassNameHere">
            <!-- The address below must be the EXACT address of your service-->
            <endpoint address ="http://localhost:19766/YourServiceName.svc" binding="webHttpBinding" bindingConfiguration="higherMessageSize" contract ="System.Data.Services.IRequestHandler">
            </endpoint>
        </service>
    </services>
    
  3. The maxReceivedMessageSize and the maxBufferSize must both be specified

    <bindings>
        <webHttpBinding>
            <!-- The maxReceivedMessageSize and the maxBufferSize must both be specified as shown below-->
            <binding name="higherMessageSize" maxReceivedMessageSize ="2048000" maxBufferSize="2048000"/>
        </webHttpBinding>
    </bindings>
    
风吹短裙飘 2024-11-09 07:15:48

编辑:这实际上可能是服务端问题。您应该确保服务配置文件的设置如得票最多的答案。 您基本上需要将 MaxReceivedMessageSize 值更改为比最大预期查询结果大小稍大的值。我必须将其设置为高达 2 MB,没有出现任何问题。

EDIT: This may actually be a service-side issue. You should ensure that service configuration file is set as shown at the answer with most votes. You basically need to change the MaxReceivedMessageSize value to something a little bigger than your largest expected query results size. I've had to set it as high as 2 MB without any issues.

枯叶蝶 2024-11-09 07:15:48

经过一番研究,我发现无法自定义数据通道服务客户端。所以我想这是不可能的。

必须创建一个普通的 wcf 客户端才能与其交互。

After some research I found no way to customise the Data channel service client. So I guess that its not possible to.

One has to create a normal wcf client to interact with it.

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