5

My WCF project uses Mtom and streaming, and set the MaxBytesPerRead to 32K (on client and server) but when I run

read = fs.read(buffer, 0, buffer.length)

it doesn't let me read more than 4096 bytes (4k) at a time (the 32K buffer doesn't fill up- it's padded with zeroes)

Is there any way I can stream my multi-megabyte file in chunks larger than 4K (please say yes) ???

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
romrom
  • 51
  • 2
  • 1
    Do you just believe that you have a performance problem, or did you really measure it? That read() returns just 4K at the time doesn't tell anything about the packet size on the network, the delay or the throughput. There are many buffers and layers between your read() and the network. – Codo Mar 01 '11 at 17:45
  • @Codo: Agreed, but it would be nice to know why 32K buffers are not working...4K seems really small. – Robert Harvey Mar 01 '11 at 17:46
  • 2
    This may provide some insight: http://stackoverflow.com/questions/451376/file-download-through-wcf-slower-than-through-iis – 500 - Internal Server Error Mar 01 '11 at 19:46

1 Answers1

2

4096 is the default size for the read buffer on a FileStream, which I assume is what your are returning. I am not really sure how the 4k limit is affecting you, but your alternative is to read the entire file into a MemoryStream and send it that way.

scottrudy
  • 1,633
  • 1
  • 14
  • 24