WCF 错误 - 已超出传入消息的最大消息大小配额 (65536) [英] WCF Error - The maximum message size quota for incoming messages (65536) has been exceeded

查看:37
本文介绍了WCF 错误 - 已超出传入消息的最大消息大小配额 (65536)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的设置:

  • 在 IIS Express 中托管的 ASP.NET 客户端
  • 在控制台应用程序中托管的 WCF 服务
  • 在管理员模式下运行 Visual Studio.NET 2012

我正在尝试从 WCF 服务返回 2 个 List 对象.当我只返回 1 个 List 对象时,我的设置工作正常.但是当我返回 2 个 List 对象时,我收到错误:

已超出传入邮件的最大邮件大小配额 (65536).要增加配额,请在适当的绑定元素上使用 MaxReceivedMessageSize 属性.

我知道这个问题已经在这个网站和其他网站上被问过很多次了.我已经尝试了几乎所有发布在互联网上的 CONFIG FILE 的各种组合,但这对我来说仍然没有奏效.

客户端配置:

<预><代码><配置><system.web><编译调试="true" targetFramework="4.0"/><httpRuntime maxRequestLength="1572864"/></system.web><system.serviceModel><客户><端点名称="basicHttpBinding"地址="http://localhost:9502/HCDataService"绑定=基本HttpBinding"bindingConfiguration="basicHttpBinding"合同="HC.APP.Common.ServiceContract.IHCServiceContract"行为配置=服务行为"></端点></客户端><绑定><基本HttpBinding><binding name="basicHttpBinding" maxBufferSize="2147483647" maxBufferPoolSize="524288" maxReceivedMessageSize="2147483647"><readerQuotas maxDepth="128" maxStringContentLength="2147483647" maxArrayLength="2147483646" maxBytesPerRead="4096" maxNameTableCharCount="16384"/></binding></basicHttpBinding></绑定><行为><端点行为><行为名称="服务行为"><dataContractSerializer maxItemsInObjectGraph="2147483647"/></行为></endpointBehaviors></行为></system.serviceModel></配置>

服务器配置:

<预><代码><配置><system.serviceModel><服务><服务名称="HC.APP.Server.Service.HCDataService" behaviorConfiguration="ServiceBehaviour"><主机><基地址><add baseAddress="http://localhost:9502/HCDataService"/></baseAddresses></host><端点名称="basicHttpBinding"地址="http://localhost:9502/HCDataService"绑定=基本HttpBinding"bindingConfiguration="basicHttpBinding"contract="HC.APP.Common.ServiceContract.IHCServiceContract"></端点></服务></服务><绑定><基本HttpBinding><binding name="basicHttpBinding" maxBufferSize="2147483647" maxReceivedMessageSize="2147483647" closeTimeout="01:50:00" openTimeout="01:50:00" sendTimeout="01:50:00" receiveTimeout="01:50:00" ><readerQuotas maxDepth="128" maxStringContentLength="8388608" maxArrayLength="2147483646" maxBytesPerRead="4096" maxNameTableCharCount="16384"/></binding></basicHttpBinding></绑定><行为><服务行为><行为名称="服务行为"><serviceDebug includeExceptionDetailInFaults="true"/><serviceMetadata httpGetEnabled="true"/><dataContractSerializer ignoreExtensionDataObject="false" maxItemsInObjectGraph="2147483646"/></行为></serviceBehaviors></行为></system.serviceModel></配置>

解决方案

那是因为您没有在服务器上指定要使用的绑定.让我们看看你的服务器配置:

下,您正在为 创建绑定配置,并将其命名为 name="basicHttpBinding".此外,您的端点名称为 <endpoint name="basicHttpBinding" ...>,其绑定为 binding="basicHttpBinding".但是,它不是指您的绑定配置,而是指绑定类型.所以,它实际上使用了 basicHttpBinding 的默认设置.

要解决此问题,首先要对端点和绑定配置进行不同的命名.例如,<endpoint name="basicEndpoint" ... ><binding name="myBasicBinding" ... >.然后,您需要使用以下属性将绑定配置分配给端点:bindingConfiguration="myBasicBinding".

这是客户端配置:

<httpRuntime maxRequestLength="32768"/></system.web><system.serviceModel><客户><端点名称=基本端点"地址="http://localhost:9502/HCDataService"绑定=基本HttpBinding"bindingConfiguration="myBasicBinding"合同="HC.APP.Common.ServiceContract.IHCServiceContract"行为配置=服务行为"></端点></客户端><绑定><基本HttpBinding><binding name="myBasicBinding" maxBufferSize="2147483647" maxBufferPoolSize="524288" maxReceivedMessageSize="2147483647"><readerQuotas maxDepth="128" maxStringContentLength="2147483647" maxArrayLength="16384" maxBytesPerRead="4096" maxNameTableCharCount="16384"/></binding></basicHttpBinding></绑定><行为><端点行为><行为名称="服务行为"><dataContractSerializer maxItemsInObjectGraph="2147483647"/></行为></endpointBehaviors></行为></system.serviceModel>

这是服务器配置:

<服务><服务名称="HC.APP.Server.Service.HCDataService" behaviorConfiguration="ServiceBehaviour"><主机><基地址><add baseAddress="http://localhost:9502/HCDataService"/></baseAddresses></host><端点名称=基本端点"地址="http://localhost:9502/HCDataService"绑定=基本HttpBinding"bindingConfiguration="myBasicBinding"contract="HC.APP.Common.ServiceContract.IHCServiceContract"></端点></服务></服务><绑定><基本HttpBinding><binding name="myBasicBinding" maxBufferSize="2147483647" maxReceivedMessageSize="2147483647" closeTimeout="01:50:00" openTimeout="01:50:00" sendTimeout="01:50:00" receiveTimeout="01:50:00" ><readerQuotas maxDepth="128" maxStringContentLength="8388608" maxArrayLength="16384" maxBytesPerRead="4096" maxNameTableCharCount="16384"/></binding></basicHttpBinding></绑定><行为><服务行为><行为名称="服务行为"><serviceDebug includeExceptionDetailInFaults="true"/><serviceMetadata httpGetEnabled="true"/><dataContractSerializer ignoreExtensionDataObject="false" maxItemsInObjectGraph="2147483646"/></行为></serviceBehaviors></行为></system.serviceModel>

不要忘记在您的客户端上更新服务引用以获得正确的配置.

My Setup:

  • ASP.NET client hosted in IIS Express
  • WCF Service hosted in Console Application
  • Running Visual Studio.NET 2012 in Admin mode

I am trying to return 2 List objects from a WCF service. My setup WORKS FINE when I return just 1 List objects. But when I return 2 List objects I get the 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 element.

I know that this question has been asked many times on this site and other sites as well. I have tried almost everything posted on the internet with various combinations of the CONFIG FILE but still this has not worked out for me.

Client Config:

<configuration>
    <system.web>
        <compilation debug="true" targetFramework="4.0" />
        <httpRuntime maxRequestLength="1572864"/>
    </system.web>

    <system.serviceModel>
        <client>
            <endpoint name="basicHttpBinding"
                address="http://localhost:9502/HCDataService"
                binding="basicHttpBinding"
                bindingConfiguration="basicHttpBinding"                
                contract="HC.APP.Common.ServiceContract.IHCServiceContract"
                behaviorConfiguration="ServiceBehaviour">
            </endpoint>
        </client>

        <bindings>
            <basicHttpBinding>
                <binding name="basicHttpBinding" maxBufferSize="2147483647" maxBufferPoolSize="524288" maxReceivedMessageSize="2147483647">
                    <readerQuotas maxDepth="128" maxStringContentLength="2147483647" maxArrayLength="2147483646" maxBytesPerRead="4096" maxNameTableCharCount="16384" />
                </binding>
            </basicHttpBinding>
        </bindings>

        <behaviors>
            <endpointBehaviors>
                <behavior name="ServiceBehaviour">
                    <dataContractSerializer maxItemsInObjectGraph="2147483647"/>
                </behavior>
            </endpointBehaviors>
        </behaviors>
    </system.serviceModel>
</configuration>

Server Config:

<configuration>
    <system.serviceModel>
        <services>
            <service name="HC.APP.Server.Service.HCDataService" behaviorConfiguration="ServiceBehaviour">
                <host>
                    <baseAddresses>
                        <add baseAddress="http://localhost:9502/HCDataService"/>
                    </baseAddresses>
                </host>

                <endpoint name="basicHttpBinding"
                    address="http://localhost:9502/HCDataService"
                    binding="basicHttpBinding"
                    bindingConfiguration="basicHttpBinding"
                    contract="HC.APP.Common.ServiceContract.IHCServiceContract">
                </endpoint>
            </service>
        </services>

        <bindings>
            <basicHttpBinding>
                <binding name="basicHttpBinding" maxBufferSize="2147483647" maxReceivedMessageSize="2147483647" closeTimeout="01:50:00" openTimeout="01:50:00" sendTimeout="01:50:00" receiveTimeout="01:50:00" >
                    <readerQuotas maxDepth="128" maxStringContentLength="8388608" maxArrayLength="2147483646" maxBytesPerRead="4096" maxNameTableCharCount="16384" />
                </binding>
            </basicHttpBinding>
        </bindings>

        <behaviors>
            <serviceBehaviors>
                <behavior name="ServiceBehaviour">
                    <serviceDebug includeExceptionDetailInFaults="true" />
                    <serviceMetadata httpGetEnabled="true" />
                    <dataContractSerializer ignoreExtensionDataObject="false" maxItemsInObjectGraph="2147483646" />
                </behavior>
            </serviceBehaviors>
        </behaviors>    
    </system.serviceModel>
</configuration>

解决方案

That would be because you didn't specify on the server which binding to use. Let's take a look at your server config:

Under <bindings> you are creating a binding configuration for <basicHttpBinding>, and you are naming it name="basicHttpBinding". Also, your endpoint name is <endpoint name="basicHttpBinding" ...> and its binding is binding="basicHttpBinding". However, it's not referring to your binding configuration, but to the binding type. So, it's actually using the default settings for basicHttpBinding.

To fix this, first of all name your endpoint and binding configuration differently. For example, <endpoint name="basicEndpoint" ... > and <binding name="myBasicBinding" ... >. Then you need to assign your binding configuration to your endpoint with this attribute: bindingConfiguration="myBasicBinding".

Here's the client config:

<system.web>
    <httpRuntime maxRequestLength="32768"/>
</system.web>

<system.serviceModel>
    <client>
        <endpoint name="basicEndpoint"
            address="http://localhost:9502/HCDataService"
            binding="basicHttpBinding"
            bindingConfiguration="myBasicBinding"
            contract="HC.APP.Common.ServiceContract.IHCServiceContract"
            behaviorConfiguration="ServiceBehaviour">
        </endpoint>
    </client>

    <bindings>
        <basicHttpBinding>
            <binding name="myBasicBinding" maxBufferSize="2147483647" maxBufferPoolSize="524288" maxReceivedMessageSize="2147483647">
                <readerQuotas maxDepth="128" maxStringContentLength="2147483647" maxArrayLength="16384" maxBytesPerRead="4096" maxNameTableCharCount="16384" />
            </binding>
        </basicHttpBinding>
    </bindings>

    <behaviors>
        <endpointBehaviors>
            <behavior name="ServiceBehaviour">
                <dataContractSerializer maxItemsInObjectGraph="2147483647"/>
            </behavior>
        </endpointBehaviors>
    </behaviors>    
</system.serviceModel>

Here's the server config:

<system.serviceModel>
    <services>
        <service name="HC.APP.Server.Service.HCDataService" behaviorConfiguration="ServiceBehaviour">
            <host>
                <baseAddresses>
                    <add baseAddress="http://localhost:9502/HCDataService"/>
                </baseAddresses>
            </host>

            <endpoint name="basicEndpoint"
                address="http://localhost:9502/HCDataService"
                binding="basicHttpBinding"
                bindingConfiguration="myBasicBinding"
                contract="HC.APP.Common.ServiceContract.IHCServiceContract">
            </endpoint>
        </service>
    </services>

    <bindings>
        <basicHttpBinding>
            <binding name="myBasicBinding" maxBufferSize="2147483647" maxReceivedMessageSize="2147483647" closeTimeout="01:50:00" openTimeout="01:50:00" sendTimeout="01:50:00" receiveTimeout="01:50:00" >
                <readerQuotas maxDepth="128" maxStringContentLength="8388608" maxArrayLength="16384" maxBytesPerRead="4096" maxNameTableCharCount="16384" />
            </binding>
        </basicHttpBinding>
    </bindings>

    <behaviors>
        <serviceBehaviors>
            <behavior name="ServiceBehaviour">
                <serviceDebug includeExceptionDetailInFaults="true" />
                <serviceMetadata httpGetEnabled="true" />
                <dataContractSerializer ignoreExtensionDataObject="false" maxItemsInObjectGraph="2147483646" />
            </behavior>
        </serviceBehaviors>
    </behaviors>
</system.serviceModel>

Don't forget to update service reference on your client to get the correct config.

这篇关于WCF 错误 - 已超出传入消息的最大消息大小配额 (65536)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆