File upload using WCF streaming, tiny reads from stream
I have implemented file upload using WCF streaming. Everything works as expected, however I ran into one problem: I allocate a 4kb buffer to read from the incoming stream, but WCF only reads 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};
}
This line has only 255 bytes: while ((count = inStream.Read (buffer, 0, buffer.Length))> 0). Is there any setting I can change or am I doing something wrong?
source to share
Submit your configs if you can. The config should specify default values ββor override values ββas shown below:
<binding name="FileTransferServicesBinding"
maxReceivedMessageSize="1048576" messageEncoding="Mtom">
<readerQuotas maxArrayLength="1048576" maxBytesPerRead="1048576"
maxNameTableCharCount="1048576" maxStringContentLength="1048576"> </readerQuotas>
</binding>
Try MSDN Link , the guy mentions that he had the same problem, only getting 255 bytes, he has an answer and seems to solve his problem. It states:
"To pass a stream to a WCF method, the Stream parameter must be the only parameter in the operation (or in the message body) ..."
source to share