代码之家  ›  专栏  ›  技术社区  ›  Daniel

设置wcf webhttp的最大消息和缓冲区大小

  •  5
  • Daniel  · 技术社区  · 15 年前

    我目前有一个带有WebHTTP绑定的WCF服务,我试图通过覆盖config中的默认设置来增加可以输入到该服务的最大大小,我尝试了如下操作

      <system.serviceModel>
    <bindings>
    <webHttpBinding>
      <binding name="webHttp" >
      <security mode="Transport">
          <transport clientCredentialType = 
                 "None"
                proxyCredentialType="None"
                realm="string" />
      </security>
      </binding>
    
    </webHttpBinding>
    </bindings>
    <services>
    
      <service name="PrimeStreamInfoServices.Service1" behaviorConfiguration="PrimeStreamInfoServices.Service1Behavior">
        <!-- Service Endpoints -->
        <endpoint address="" binding="webHttpBinding"  contract="PrimeStreamInfoServices.IService1">
          <!-- 
              Upon deployment, the following identity element should be removed or replaced to reflect the 
              identity under which the deployed service runs.  If removed, WCF will infer an appropriate identity 
              automatically.
          -->
        </endpoint>
        <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
      </service>
    </services>
    <behaviors>
      <serviceBehaviors>
        <behavior name="PrimeStreamInfoServices.Service1Behavior">
          <!-- To avoid disclosing metadata information, set the value below to false and remove the metadata endpoint above before deployment -->
          <serviceMetadata httpGetEnabled="true"/>
          <!-- To receive exception details in faults for debugging purposes, set the value below to true.  Set to false before deployment to avoid disclosing exception information -->
          <serviceDebug includeExceptionDetailInFaults="false"/>
        </behavior>
      </serviceBehaviors>
    </behaviors>
    <diagnostics>
    

    设置与消息大小相关的各种其他属性,但似乎都不起作用,是否可以更改WebHTTP绑定的消息大小? 有什么建议吗?谢谢!

    2 回复  |  直到 7 年前
        1
  •  12
  •   marc_s HarisH Sharma    15 年前

    根据您的设置,有多种设置可能会产生影响-请尝试以下操作:

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

    通过定义webhttpbinding的“版本”并将所有这些参数设置为更高的值,您应该能够通过任何消息大小(几乎)。

    提醒你:这确实会让你的系统暴露出被大量信息淹没的可能性,并因此而陷入瘫痪(经典的拒绝服务攻击)——这就是为什么这些限制被设置得相当低的原因——由设计和故意。

    你可以把它们改成更高的价值观——只要知道你在做什么,如果你这样做的话,安全风险是什么!

    马克

    ps:为了使用这些设置,您当然必须在服务器和客户端配置中引用绑定配置:

    <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>
    
        2
  •  0
  •   Pang firemonkey    7 年前

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