Stream 100 gig file over WCF? - wcf

Can I stream 100 Gig file over WCF to an IIS WebService? I am running into
The maximum message size quota for incoming messages (2147483647) has
been exceeded. TO increase the quota, use the MaxReceivedMessageSize
property.
The only problem with that advice is I think I have it set to the max value.

The key is to be sure you are using transferMode="Streamed" (Buffered which is the default will give you OutOfMemoryException) and set MaxReceivedMessageSize to be very large it can hold a long. The real gotcha is that when you do a "Configure Service Reference" sometimes it will remove transferMode="Streamed" and revert you back the default Buffered

Related

WCF Message Size Specification

What is Maximum message size (in MB) of incoming and outgoing messages.
maxReceivedMessageSize (what is MAX value we can set with this configuration for basichttp binding)
Run the test client and scroll to the bottom. If you double click the Config File node you will see the XML representation. As you can see the maxReceivedMessageSize is 65536.
the limit is Int64.MaxValue1 which is: 9223372036854775807.

I keep getting a maximum message size quota for incominng messages (65536) has been exceeded even though I have set mine high

I keep getting this error...
The maximum message size quota for incoming messages (65536) has been
exceeded. To increase the quota, use the MaxReceivedMessageSize
property on the appropriate binding element.
Even though I have my MaxReceivedMessageSize equal to 2147483647... Which is almost an order of magnitude greater than that first number. What on earth is going on?
Did you adjust MaxReceivedMessageSize on both the client-side and server-side?

Will the maximum limit of configuration property MaxReceivedMessageSize in wcf affects service performance?

I'm getting the following communication exception for my wcf service making cal to another wcf service:
"The maximum message size quota for incoming messages (65536) has been exceeded. To increase the quota, use the MaxReceivedMessageSize property on the appropriate binding element."
I resolved this by increasing the size as below:
maxReceivedMessageSize="50000000"
But, here I want to know whether any side effects of increasing message size to such big level.
Yes - it might. The reason WCF keeps this limit low (64K) by default is this: imagine your server is busy responding to requests, say dozens or hundreds, and they all require the maximum message size.
Potentially, your server could have to allocate dozens or hundreds of message buffers at the same time - if you have 100 users and each requests 64K, that's 6.4 MByte - but if you have 200 users and each requests 5 MB - that's a gigabyte of RAM in the server - just for the message buffers, for one service.
So yes - putting a limit on the max message size does make sense and it helps manage your server's memory consumption (and thus performance). If you open it up too wide, an attacker might just do such an attack - flooding your server with bogus requests, each allocating as much memory as they can get, ultimately bringing your server down (Denial of Service attacks like that are quite common).
You need to increase the quota according to the web service. One side effect I can think of if you use very large values is that memory usage will increase but you can safely increase it to a suitable value without any adverse effects.

No exceptions thrown even when maxBufferSize value is smaller than the response message size in WCF

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.
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.

WCF readerQuotas settings - drawbacks?

If a WCF service returns a byte array in its response message, there's a chance the data will exceed the default length of 16384 bytes. When this happens, the exception will be something like
The maximum array length quota (16384)
has been exceeded while reading XML
data. This quota may be increased by
changing the MaxArrayLength property
on the XmlDictionaryReaderQuotas
object used when creating the XML
reader.
All the advice I've seen on the web is just to increase the settings in the <readerQuotas> element to their maximum, so something like
<readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647"
maxArrayLength="2147483647" maxBytesPerRead="2147483647"
maxNameTableCharCount="2147483647" />
on the server, and similar on the client.
I would like to know of any drawbacks with this approach, particularly if the size of the byte array may only occassionally get very large. Do the settings above just make WCF declare a huge array for each request? Do you have to limit the maximum size of the data returned, or can you just specify a reasonably-sized buffer and get WCF to keep going until all the data is read?
Thanks!
The main drawback is a potential vulnerability to attacks - e.g. a malicious source can now flood your webserver with message up to 2 GB in size and potentially bring it down.
Of course, allowing 2 GB messages also puts some strain on your server in terms of memory consumption, since those messages need to be assembled in memory, in full (unless you use streaming protocols in WCF). If you have 10 clients sending you 2 GB messages, you'll need plenty of RAM on your server! :-)
Other than that, I don't see any real issues.
Marc
There is an article on MSDN which explains the various security considerations you need to think about when setting these values. Some denial-of-service attacks are those which eat up your memory and some of them (such as MaxDepth not being set properly) could cause fatal StackOverflowExceptions which could bring down your server in a single request.
http://msdn.microsoft.com/en-us/library/ms733135.aspx