简体   繁体   English

在DataServiceContext中更改最大消息大小

[英]Change max message size in DataServiceContext

I am using DataServiceContext to get data from a wcf service which is hosting a dbml. 我正在使用DataServiceContext从承载dbml的wcf服务获取数据。 It works fine in general but queries that return large amounts of data (eg binary files) create the usual WCF error: 通常它可以正常工作,但是返回大量数据(例如二进制文件)的查询会产生通常的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 

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 其中RPDataModelDataContext是使用entityframework生成的客户端代理类

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

Can anyone point me to the right direction? 谁能指出我正确的方向?

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. 您必须准确指定服务name This should be the fully qualified service name. 这应该是完全合格的服务名称。 (ie. Namespace.ClassName ) (即Namespace.ClassName
  2. You MUST provide the EXACT address of the endpoint. 您必须提供端点的确切address (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 必须同时指定maxReceivedMessageSizemaxBufferSize

     <bindings> <webHttpBinding> <!-- The maxReceivedMessageSize and the maxBufferSize must both be specified as shown below--> <binding name="higherMessageSize" maxReceivedMessageSize ="2048000" maxBufferSize="2048000"/> </webHttpBinding> </bindings> 

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. 基本上,您需要将MaxReceivedMessageSize值更改为比最大预期查询结果大小大一些的值。 I've had to set it as high as 2 MB without any issues. 我不得不将其设置为2 MB,没有任何问题。

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. 必须创建一个普通的wcf客户端与之交互。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM