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

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

问题描述

我的设置:


  • IIS Express中托管的ASP.NET客户端

  • 托管的WCF服务在控制台应用程序中

  • 在管理模式下运行Visual Studio.NET 2012

我正在尝试从WCF服务返回2个列表对象。当我仅返回1个List对象时,我的设置会起作用。但是当我返回2个列表对象时,我得到了错误:

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:

已超过传入消息的最大消息大小配额(65536)。要增加配额,请在适当的绑定元素上使用MaxReceivedMessageSize属性。

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.

客户端配置:

<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>

服务器配置:

<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:

< bindings> 下,您正在为< basicHttpBinding> ,而您将其命名为 name = basicHttpBinding 。另外,您的端点名称是<端点名称= basicHttpBinding ...> ,其绑定是 binding = basicHttpBinding 但是不是指您的绑定配置,而是指绑定类型。因此,它实际上使用的是 basicHttpBinding 的默认设置。

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.

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

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".

这是客户端配置:

<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>

这是服务器配置:

<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天全站免登陆