The max message size quota for incoming messages (65536) …To increase the quota, use the MaxReceivedMessageSize property

。_饼干妹妹 提交于 2019-11-27 14:35:13

问题


I got this crazy problem I'm trying to deal with. I know that when we're getting huge amount of data we must increase the quota on client .config file, but what am I supposed to do if my client is sending huge data "to" the WCF server?

It works perfectly normal when I'm sending small sized input parameter. Unfortunately, it breaks down when the input grows bigger.

Debugger it says:

Bad Request, 400;

on trace file it is:

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.

Is there some way to increase this quota of incomming data on the server side? if so, how?

Here's my sample config related parts:

<bindings>
  <basicHttpBinding>
    <binding name="MyBasicHttpBinding"
        closeTimeout="00:01:00" openTimeout="00:01:00" receiveTimeout="00:10:00"
        sendTimeout="00:01:00" allowCookies="false" bypassProxyOnLocal="false"
        hostNameComparisonMode="StrongWildcard" maxBufferSize="2147483647"
        maxBufferPoolSize="2147483647" maxReceivedMessageSize="2147483647"
        messageEncoding="Text" textEncoding="utf-8" transferMode="Buffered"
        useDefaultWebProxy="true">
      <readerQuotas maxDepth="64" maxStringContentLength="2147483647" maxArrayLength="2147483647"
          maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647"  />
      <security mode="None">
        <transport clientCredentialType="None" proxyCredentialType="None"
            realm="" />
        <message clientCredentialType="UserName" algorithmSuite="Default" />
      </security>
    </binding>

  </basicHttpBinding>
</bindings>

 <services>
  <service name="MyWcfService">
    <endpoint address="http://myservice..."
      binding="basicHttpBinding" bindingConfiguration="MyBasicHttpBinding"
      name="MyBasicHttpBinding" contract="IMyContract" />
  </service>
</services> 

and here's my client-side code (I create it dynamically):

        var binding = new BasicHttpBinding();
        binding.MaxBufferPoolSize = 2147483647;
        binding.MaxBufferSize = 2147483647;
        binding.MaxReceivedMessageSize = 2147483647;
        binding.ReaderQuotas.MaxStringContentLength = 2147483647;
        binding.ReaderQuotas.MaxArrayLength = 2147483647;
        binding.ReaderQuotas.MaxDepth = 2147483647;
        binding.ReaderQuotas.MaxBytesPerRead = 2147483647;


        var address = new EndpointAddress("http://mylocalservice.."); 

        ChannelFactory<IMyContract> factory = new ChannelFactory<IMyContract>(binding, address);

        foreach (OperationDescription op in factory.Endpoint.Contract.Operations)
        {
            DataContractSerializerOperationBehavior dataContractBehavior =
                        op.Behaviors.Find<DataContractSerializerOperationBehavior>()
                        as DataContractSerializerOperationBehavior;
            if (dataContractBehavior != null)
            {
                dataContractBehavior.MaxItemsInObjectGraph = 2147483646;
            }
        }
        public IMyContract MyClientObject = factory.CreateChannel();

回答1:


You can set the MaxReceivedMessageSize property on the service via the service's config file.

Setting the client's MaxReceivedMessageSize only affects messages received by the client; it has no effect on messages received by the service. Correspondingly, to allow the service to receive large messages, you need to set the service's config file.

Sample Service Config

<system.serviceModel>
  <bindings>
    <wsHttpBinding>
      <binding name="MyBinding" maxReceivedMessageSize="2147483647" />
    </wsHttpBinding>
  </bindings>
  <services>
    <service name="MyService">
      <endpoint address="http://myservice" binding="wsHttpBinding"
                bindingConfiguration="MyBinding" contract="IMyServiceContract" />
    </service>
  </services>
</system.serviceModel>

The above is a very stripped down config file, but shows the relevant parts. The important part is that you define the binding and give it a name, and set any values explicitly that are different from the defaults, and use that name in the bindingConfiguration attribute on the endpoint element.




回答2:


My problem was with the wcf test client. For some reason, it wouldn't generate a client config with the increased maxReceivedMessageSize. My fix was to right click "Config file" -> "Edit with SvcConfigEditor" -> bindings -> maxReceivedMessageSize.




回答3:


This issue can be resolved by adding the below additional binding node to the binding section of config file.

<basicHttpBinding>
  <binding maxBufferSize="2147483647" maxBufferPoolSize="2147483647" maxReceivedMessageSize="2147483647">
    <readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647" maxArrayLength="2147483647" 
       maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" />
  </binding>
</basicHttpBinding>


来源:https://stackoverflow.com/questions/8382392/the-max-message-size-quota-for-incoming-messages-65536-to-increase-the-quo

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!