WCF maxBytesPerRead limit to 4096

一曲冷凌霜 提交于 2019-12-21 21:21:20

问题


I am using basic WCF web service in steaming mode to download files from server.

I have specified binding on server side as

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

and my client side binding xml looks like

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

I am trying to download files using

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

Even though I have specified maxBytesPerRead="8192", max bytes that I can read in a call is only 4096.


回答1:


Unless you have very specific security requirements, you might want to consider setting the maximum sizes to Int32.MaxValue. It will save you some debugging time. Then tune it down to a more reasonable value if needed.



来源:https://stackoverflow.com/questions/3746638/wcf-maxbytesperread-limit-to-4096

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!