Reputation: 375
I am implementing a large file streaming application using WCF.
I got a issue when I set the configuration for MaxReceivedMessageSize and MaxBufferSize. When these parameters are same system works fine. But when I chose different value it gives an error message,
For TransferMode.Buffered, MaxReceivedMessageSize and MaxBufferSize must be the same value.
But I confused with the information in http://msdn.microsoft.com/en-us/library/ms733742.aspx as follows,
For example, suppose your service must receive files up to 4 GB in size and store them on the local disk. Suppose also that your memory is constrained in such a way that you can only buffer 64 KB of data at a time. Then you would set the MaxReceivedMessageSize to 4 GB and MaxBufferSize to 64 KB. Also, in your service implementation, you must ensure that you read only from the incoming stream in 64-KB chunks and do not read the next chunk before the previous one has been written to disk and discarded from memory.to 4 GB and MaxBufferSize to 64 KB. Also, in your service implementation, you must ensure that you read only from the incoming stream in 64-KB chunks and do not read the next chunk before the previous one has been written to disk and discarded from memory.
Can anybody explain the reason of this matter?
Upvotes: 2
Views: 6293
Reputation: 7817
It's because of the TransferMode. You should set it to streamed, if you want to use a different buffer size than message size.
transports support two modes of transferring messages in each direction:
Buffered transfers hold the entire message in a memory buffer until the transfer is complete.
Streamed transfers only buffer the message headers and expose the message body as a stream, from which smaller portions can be read at a time.
Upvotes: 6