Setting Max Message and buffer size for WCF webhttp

前端 未结 3 812
长发绾君心
长发绾君心 2020-12-05 21:56

I currently have a WCF service with webHttp bindings, im attempting to increase the max size that can be inputted to the service by overriding the default settings in config

相关标签:
3条回答
  • 2020-12-05 22:08

    Setting Max Message and buffer size for WCF Rest services webhttpbinding

    <bindings>
      <webHttpBinding>
        <binding maxBufferPoolSize="2147483647" maxReceivedMessageSize="2147483647">
          <readerQuotas maxDepth="200" maxStringContentLength="83886089" maxArrayLength="163841" maxBytesPerRead="2147483647" maxNameTableCharCount="16384"/>
        </binding>
      </webHttpBinding>
    </bindings>
    
    0 讨论(0)
  • 2020-12-05 22:16

    There's a multitude of settings that might have an influence depending on your settings - try this:

    <bindings>
      <webHttpBinding>
        <binding name="LargeWeb"
                 maxBufferPoolSize="1500000"
                 maxReceivedMessageSize="1500000"
                 maxBufferSize="1500000">
          <readerQuotas 
                maxArrayLength="656000"
                maxBytesPerRead="656000"
                maxDepth="32"
                maxNameTableCharCount="656000"
                maxStringContentLength="656000"
                />
        </binding>
      </webHttpBinding>
    </bindings>
    

    By defining your "version" of the webHttpBinding and setting all those parameters to higher values, you should be able to get through any message size (almost).

    Mind you: this does open up your system to the potential of being flooded with huge messages and thus be brought down to its knees (classic denial-of-service attacks) - that's the reason these limits are set fairly low - by design and on purpose.

    You can change them to higher values - just be aware what you're doing and what the security risks are, if you do!

    Marc

    PS: In order to make use of these settings, you of course have to reference that binding configuration in your server and client side configs:

    <client>
      <endpoint address="http://localhost"
                binding="webHttpBinding" bindingConfiguration="LargeWeb"
                contract="IMyService" />
    </client>
    <services>
      <service>
        <endpoint address="http://localhost"
                  binding="webHttpBinding" bindingConfiguration="LargeWeb"
                  contract="IMyService" />
      </service>
    </services>
    
    0 讨论(0)
  • 2020-12-05 22:24

    If you are using [DataContract] decorator in your model, you need to add yhe dataContractSerializer into your web.config

    Example:

      <serviceBehaviors>
        <behavior name="ServiceBehavior">
          <serviceMetadata httpsGetEnabled="false"   httpGetEnabled="true"/>
          <serviceDebug includeExceptionDetailInFaults="true"/>
          <dataContractSerializer maxItemsInObjectGraph="2147483647" />
        </behavior>
      </serviceBehaviors>
    
    0 讨论(0)
提交回复
热议问题