views:

242

answers:

1

Hi,

I have a wcf operation that sends byte array to client.

The maximum size of byte array I intend to send is 2mb. So I have set maxbuffersize and maxreceivedmessagesize to 2097152 (2 mb) on basichttpbinding with transfermode=buffered on the server.

Despite these settings, no buffer overflow exception is getting thrown if I transfer a 17mb file?

Thanks.

+1  A: 

UPDATE:
My understanding of the buffering in WCF and the effect of the various values was wrong. Please check out this MSDN thread and this related blog post on the ins and outs of WCF buffer management.

However, I still cannot find a definitive answer on how to limit the buffers on the server. From what I understand, if you limit maxBufferPoolSize (total for the pool of all buffers) and maxBufferSize (max. size for a single buffer) on the server side, you should be able to achieve what you're trying to do.

So in your case, you should set maxBufferSize to 2mb on the server, and maxBufferPoolSize to 2mb or more, also on the server. On the client, set the maxReceivedMessageSize also to 2mb.

marc_s
It works when I send a 17mb file to the client.The maxreceivedmessagesize and maxbuffersize at the client are set to 2gb. If I set these values to 2mb at the client I get an exception because client cannot receive 17mb file but the idea is not to restrict the client receiving large messages. The idea is to control the buffer size on the server.
kshatriyudu00
from what I read - By default, WCF processes messages in buffered mode. This means that the entire content of a message is present in memory before it is sent or after it is received.How do I control this memory allocated? I thought I could control this by maxbuffersize property but apparently not?
kshatriyudu00
Agreed that the mesage is always assembled in full in buffered mode. My intention is not to send messages in chunks for which I could have used chunkingchannel.Setting 2mb on the client will not stop server process a 17mb file. The server still processes the 17mb file (17mb sitting in meomory) and tries to send it to the client but the client can't receive it because the maxrecievedmessagesize is set to 2mb and hence error is thrown at the client not on the server.
kshatriyudu00
The idea is to reduce memory consumption on the server i.e. only send max of 2 mb of byte[] to client. I can control this by finding out the file size and not sending the file to client if size > 2mb.I was hoping if WCF could handle all this.
kshatriyudu00