WCF maxBytesPerRead上限为4096 [英] WCF maxBytesPerRead limit to 4096

查看:572
本文介绍了WCF maxBytesPerRead上限为4096的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在热气腾腾的方式从服务器下载文件使用基本WCF Web服务。



我已经指定为


服务器端绑定

 <&basicHttpBinding的GT; 
<绑定名称=DBUpdateServiceBindingcloseTimeout =23时59分59秒
openTimeout =23时59分59秒receiveTimeout =23时59分59秒的SendTimeout =23时59分: 59
maxReceivedMessageSize =10067108864messageEncoding =MTOM
transferMode =流>
< readerQuotas MAXDEPTH =32maxStringContentLength =8192maxArrayLength =16384
maxBytesPerRead =8192maxNameTableCharCount =16384/>
< /&结合GT;
< / basicHttpBinding的>

和我的客户端绑定XML看起来像

 <&绑定GT; 
<&basicHttpBinding的GT;
<绑定名称=WScloseTimeout =23:59:59openTimeout =23:59:59
receiveTimeout =23:59:59的SendTimeout =23:59: 59maxReceivedMessageSize =10067108864
messageEncoding =MTOMtransferMode =流>
< readerQuotas MAXDEPTH =32maxStringContentLength =8192maxArrayLength =16384
maxBytesPerRead =8192maxNameTableCharCount =16384/>
<安全>
<运输境界=/>
< /安全>
< /&结合GT;
< / basicHttpBinding的>
< /绑定>



我试图用



<$下载文件p $ p> 字节[]缓冲区=新的字节[32768]
,而(真)
{
INT读= serverStream.Read(缓冲,0,buffer.Length);
如果(读< = 0)
中断;
fs.Write(缓冲,0,读);
}

尽管我已经指定maxBytesPerRead =8192,最大字节数,我可以在通话中读的是只有4096。


解决方案

除非你有非常具体的安全要求,您可能要考虑设置最大尺寸为Int32.MaxValue。它会为你节省一些调试时间。然后调下来到如果需要一个更加合理的值。


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.

解决方案

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.

这篇关于WCF maxBytesPerRead上限为4096的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆