7

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

4

3 回答 3

12

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

<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>
于 2009-07-27T16:26:28.763 回答
0

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

<bindings>
  <webHttpBinding>
    <binding maxBufferPoolSize="2147483647" maxReceivedMessageSize="2147483647">
      <readerQuotas maxDepth="200" maxStringContentLength="83886089" maxArrayLength="163841" maxBytesPerRead="2147483647" maxNameTableCharCount="16384"/>
    </binding>
  </webHttpBinding>
</bindings>
于 2017-08-26T09:04:26.973 回答
0

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

例子:

  <serviceBehaviors>
    <behavior name="ServiceBehavior">
      <serviceMetadata httpsGetEnabled="false"   httpGetEnabled="true"/>
      <serviceDebug includeExceptionDetailInFaults="true"/>
      <dataContractSerializer maxItemsInObjectGraph="2147483647" />
    </behavior>
  </serviceBehaviors>
于 2020-09-07T23:34:55.727 回答