【问题标题】:Setting Max Message and buffer size for WCF webhttp为 WCF webhttp 设置最大消息和缓冲区大小
【发布时间】:2010-11-14 09:28:56
【问题描述】:

我目前有一个带有 webHttp 绑定的 WCF 服务,我试图通过覆盖配置中的默认设置来增加可以输入服务的最大大小,我尝试过类似的操作

  <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 绑定的消息大小吗? 有什么建议?谢谢!

【问题讨论】:

  • 你能把你的配置文件的相关部分贴出来吗?

标签: wcf size message webhttp


【解决方案1】:

如果您在模型中使用 [DataContract] 装饰器,则需要将 dataContractSerializer 添加到您的 web.config

例子:

  <serviceBehaviors>
    <behavior name="ServiceBehavior">
      <serviceMetadata httpsGetEnabled="false"   httpGetEnabled="true"/>
      <serviceDebug includeExceptionDetailInFaults="true"/>
      <dataContractSerializer maxItemsInObjectGraph="2147483647" />
    </behavior>
  </serviceBehaviors>

【讨论】:

    【解决方案2】:

    为 WCF Rest 服务 webhttpbinding 设置最大消息和缓冲区大小

    <bindings>
      <webHttpBinding>
        <binding maxBufferPoolSize="2147483647" maxReceivedMessageSize="2147483647">
          <readerQuotas maxDepth="200" maxStringContentLength="83886089" maxArrayLength="163841" maxBytesPerRead="2147483647" maxNameTableCharCount="16384"/>
        </binding>
      </webHttpBinding>
    </bindings>
    

    【讨论】:

      【解决方案3】:

      有许多设置可能会根据您的设置产生影响 - 试试这个:

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

      【讨论】:

      • 这不起作用,它不会让我发送任何大于 64k 的东西
      • 你能显示你的配置吗?你引用过这个绑定配置吗?
      • 是的,我意识到这是我的问题,我刚刚添加了整个配置,但是当我放置 bindingCONfiguration 属性时,由于某种原因,我得到了一个异常
      • 我刚刚发现它是因为我在那里的安全标签...你会通过查看配置的 sn-p 知道为什么它不喜欢那里的安全设置吗?谢谢!
      • 您指定了传输安全性,例如您想使用 Https - 这需要在客户端上进行一些设置(SSL 证书等)。我认为这可能是问题所在。
      猜你喜欢
      • 1970-01-01
      • 2012-03-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2010-09-27
      • 1970-01-01
      • 2013-09-01
      • 1970-01-01
      相关资源
      最近更新 更多