c# - 更改 DataServiceContext 中的最大消息大小

标签 c# wcf entity-framework wcf-data-services

我正在使用 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 

问题是我找不到更改 channel 消息大小的方法。

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

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

其中RPDataModelDataContext是用entityframework生成的客户端代理类

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

谁能指出我正确的方向?

最佳答案

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

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

    <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. 必须指定 maxReceivedMessageSizemaxBufferSize

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

关于c# - 更改 DataServiceContext 中的最大消息大小,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5718030/

相关文章:

c# - SelectCommand.Connection 属性尚未初始化

c# - 如何将 C# dll 注入(inject)另一个进程

c# - 如何合并两个列表而不重复? (可能的二人组)

c# - WCF服务库: BadImageFormatException with 32 bit dll

c# - LINQ .Sum() 返回不正确的数据

C#ArgumentOutOfRangeException异常

c# - 使用 WCF 的身份验证服务

wcf - Windows 手机 : Upload Progress

c# - 如何在单元测试中使用 Moq 和 DbFunctions 来防止 NotSupportedException?

c# - Azure函数无法在没有实体提供程序的情况下使用连接字符串