WCF错误 - 最大消息大小配额用于传入消息(65536)已被超过[重复](WCF Error -

2019-09-01 07:36发布

这个问题已经在这里有一个答案:

  • 进来的消息的最大消息大小配额(65536)已被超过 2个答案

我的设置:

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

我想从一个WCF服务回报2个List对象。 当我回来只是1 List对象我的设置工作正常。 但是,当我回到2个List对象我得到的错误:

的最大消息大小配额用于传入消息(65536)已经被超过。 为了增加配额,请使用相应绑定元素上MaxReceivedMessageSize财产。

我知道,这个问题已经被问了很多次在本网站和其他网站也是如此。 我已经试过几乎所有贴有这并没有为我工作了配置文件中的各种组合,但仍然在互联网上。

客户端配置:

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

Answer 1:

这将是因为你没有它结合使用服务器上指定。 让我们来看看你的服务器配置:

<bindings>正在创建要绑定配置<basicHttpBinding> ,并且您将其命名为name="basicHttpBinding" 。 此外,你的端点名称是<endpoint name="basicHttpBinding" ...>及其绑定binding="basicHttpBinding"然而 ,它不是指你的绑定配置 ,但在绑定类型 。 那么,它的实际使用默认设置basicHttpBinding

为了解决这个问题,首先命名您的端点和不同的绑定配置。 例如, <endpoint name="basicEndpoint" ... ><binding name="myBasicBinding" ... > 然后,你需要你的绑定配置与此属性分配给您的端点: 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>

不要忘了update service reference您的客户端上,以得到正确的配置。



文章来源: WCF Error - The maximum message size quota for incoming messages (65536) has been exceeded [duplicate]