首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >设置WCF webhttp的最大消息和缓冲区大小

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

Stack Overflow用户
提问于 2009-07-27 15:10:26
回答 3查看 34.7K关注 0票数 7

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

代码语言:javascript
复制
  <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绑定的消息大小吗?有什么建议吗?谢谢!

EN

回答 3

Stack Overflow用户

回答已采纳

发布于 2009-07-27 16:26:29

有许多设置可能会对你的设置产生影响--试试这个:

代码语言:javascript
复制
<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的“版本”并将所有这些参数设置为更高的值,您应该能够通过任何消息大小(几乎)。

提醒你:这确实会让你的系统面临被大量消息淹没的可能性,并因此陷入瘫痪(经典的拒绝服务攻击)-这就是这些限制被设置得相当低的原因-无论是设计上的还是故意的。

您可以将它们更改为更高的值-只要知道您在做什么,如果您这样做了,安全风险是什么!

Marc

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

代码语言:javascript
复制
<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>
票数 12
EN

Stack Overflow用户

发布于 2017-08-26 17:04:27

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

代码语言:javascript
复制
<bindings>
  <webHttpBinding>
    <binding maxBufferPoolSize="2147483647" maxReceivedMessageSize="2147483647">
      <readerQuotas maxDepth="200" maxStringContentLength="83886089" maxArrayLength="163841" maxBytesPerRead="2147483647" maxNameTableCharCount="16384"/>
    </binding>
  </webHttpBinding>
</bindings>
票数 0
EN

Stack Overflow用户

发布于 2020-09-08 07:34:56

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

示例:

代码语言:javascript
复制
  <serviceBehaviors>
    <behavior name="ServiceBehavior">
      <serviceMetadata httpsGetEnabled="false"   httpGetEnabled="true"/>
      <serviceDebug includeExceptionDetailInFaults="true"/>
      <dataContractSerializer maxItemsInObjectGraph="2147483647" />
    </behavior>
  </serviceBehaviors>
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/1188731

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档