views:

1152

answers:

1

Hi

I've implemented file uploading using WCF's streaming. Everything works as expected, however i faced one issue: i'm allocating 4kb buffer to read from incoming stream, but WCF reads only 255 bytes. Here is my upload function:

public UploadResponse UploadFile(FileDto fileDto)
     {
      using (var inStream = fileDto.FileStream)
      using (var outStream = new FileStream("OutFile.txt", FileMode.Create))
      {
       var buffer = new byte[4096];
       int count;
       while ((count = inStream.Read(buffer, 0, buffer.Length)) > 0)
       {
        outStream.Write(buffer, 0, count);
       }
      }
      return new UploadResponse {DocumentId = -1};
     }

Only 255 bytes reading at this line: while ((count = inStream.Read(buffer, 0, buffer.Length)) > 0). Is there any setting i can change, or am i doing something wrong?

+1  A: 

Post your configs if you can please. The config should specify the defaults or overriden values, something like below:

    <binding name="FileTransferServicesBinding"
 maxReceivedMessageSize="1048576" messageEncoding="Mtom">
      <readerQuotas maxArrayLength="1048576" maxBytesPerRead="1048576"
 maxNameTableCharCount="1048576" maxStringContentLength="1048576"> </readerQuotas>
    </binding>

Try this MSDN Link the guy mentions that he had the same issue with only getting 255 bytes, he has an answer marked and it seems to resolve his issue. It states:

"In order to pass a stream to a WCF method, the Stream parameter must be the only parameter in the operation (or in the message body)..."

Tanner
I did not tried readerQuotas. Thanks for the sample. I'll try it and get back with results.
andrew_m
The default value for maxBytesPerRead is 4096 though, so I'm not so sure that's going to be the problem.
Drew Marsh
Check the links in my post here: http://stackoverflow.com/questions/898168/supported-bindings-for-wcf-streaming-transfers/911371#911371
Tanner
I tried to set maxBytesPerRead and other quotas to higher values, but without success. Still WCF reads only 255 bytes from incoming stream. I found this link http://forums.asp.net/p/1359234/2803427.aspx. Seems like same problem.
andrew_m