【问题标题】:WCF maxBytesPerRead limit to 4096WCF maxBytesPerRead 限制为 4096
【发布时间】:2010-09-19 17:08:16
【问题描述】:

我正在使用蒸汽模式下的基本 WCF Web 服务从服务器下载文件。

我已将服务器端的绑定指定为

     <basicHttpBinding>
        <binding name="DBUpdateServiceBinding" closeTimeout="23:59:59"
           openTimeout="23:59:59" receiveTimeout="23:59:59" sendTimeout="23:59:59"
           maxReceivedMessageSize="10067108864" messageEncoding="Mtom"
           transferMode="Streamed">
           <readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"
              maxBytesPerRead="8192" maxNameTableCharCount="16384" />
        </binding>
     </basicHttpBinding>

我的客户端绑定 xml 看起来像

  <bindings>
     <basicHttpBinding>
        <binding name="ws" closeTimeout="23:59:59" openTimeout="23:59:59"
           receiveTimeout="23:59:59" sendTimeout="23:59:59" maxReceivedMessageSize="10067108864"
           messageEncoding="Mtom" transferMode="Streamed">
           <readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"
              maxBytesPerRead="8192" maxNameTableCharCount="16384" />
           <security>
              <transport realm="" />
           </security>
        </binding>
     </basicHttpBinding>
  </bindings>

我正在尝试使用

下载文件
   byte[] buffer = new byte[32768];
   while (true)
   {
      int read = serverStream.Read(buffer, 0, buffer.Length);
      if (read <= 0)
         break;
      fs.Write(buffer, 0, read);
   }

即使我指定了 maxBytesPerRead="8192",我在调用中可以读取的最大字节数也只有 4096。

【问题讨论】:

  • 您确定这些绑定配置确实被您的服务和客户端端点使用了吗??
  • 是的,我很确定。没有定义其他配置。
  • 是web.config中的maxRequestLength吗?
  • 您的客户端创建代码是什么样的?如果您没有调用默认构造函数,则可能没有使用 app.config 中指定的配置。

标签: c# wcf wcf-binding


【解决方案1】:

除非您有非常具体的安全要求,否则您可能需要考虑将最大大小设置为 Int32.MaxValue。它将为您节省一些调试时间。然后根据需要将其调低到更合理的值。

【讨论】:

  • 这不能回答 maxBytesPerRead 卡在 4096 的问题,无论您将其设置为什么(与 Streamed 和 MTOM 结合使用)
猜你喜欢
  • 2013-03-06
  • 1970-01-01
  • 1970-01-01
  • 2010-09-16
  • 2017-09-22
  • 2016-02-25
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多