更改 DataServiceContext 中的最大消息大小
我正在使用 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我在这方面也遇到了很多问题。我遗漏了三个细节。
名称
。这应该是完全限定的服务名称。 (即Namespace.ClassName)您必须提供端点的确切
地址
。 (见下面的代码)<前><代码><服务>;
<服务名称=“YourDomainNameHere.YourClassNameHere”>
<端点地址=“http://localhost:19766/YourServiceName.svc”绑定=“webHttpBinding”绑定配置=“higherMessageSize”合同=“System.Data.Services.IRequestHandler”>
必须指定
maxReceivedMessageSize
和maxBufferSize
<前><代码><绑定>;
<绑定名称=“higherMessageSize”maxReceivedMessageSize=“2048000”maxBufferSize=“2048000”/>
I was having tons of problems with this one as well. There were three details I was missing.
name
exactly. This should be the fully qualified service name. (ie. Namespace.ClassName)You MUST provide the EXACT
address
of the endpoint. (See code below)The
maxReceivedMessageSize
and themaxBufferSize
must both be specified编辑:这实际上可能是服务端问题。您应该确保服务配置文件的设置如得票最多的答案。 您基本上需要将 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.
经过一番研究,我发现无法自定义数据通道服务客户端。所以我想这是不可能的。
必须创建一个普通的 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.