WCF maxBytesPerRead limit to 4096
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 by开发者_开发技巧tes 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.
精彩评论