Wednesday, 8 August 2012

WCF MaxReceivedMessageSize max value in .config

MaxReceivedMessageSize parameter in binding config  file: 

For max file size in WCF, we need to set following parameter in binding files.
<binding name="MyService"
       maxBufferSize="2147483647" transferMode="Streamed" >
       <readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647"
     maxArrayLength="2147483647" maxBytesPerRead="2147483647"
<!-- other binding info here, such as security -->

Max possible size: MaxReceivedMessageSize to 2147483647 (i.e. Int32.MaxValue), which is 2GB
For our case, as we are using WsHttpBinding.
        <binding name="wsHttpBindingSettings" maxReceivedMessageSize="2147483647">
          <readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647"
            maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" />
Please Note:
1.       But it’s recommended that the file size should be less, as the data is transferred through network there is possibility of slow network performance.

2.       We can set it to the maximum value, which is 2GB (2147483647) - or if we’re using streamed transfers we can go up to 263 bytes (almost 10,000,000 terabytes). But remember that by setting it to a value larger than necessary we may be opening our service (or client) to attacks.
3.       Only if the service is expected to receive messages larger than 65536 bytes. And in this case, we’d be increasing MaxReceivedMessageSize on the endpoints where we expect to receive such big messages.
4.       If the messages that our client/servers expect to receive are larger than the default value for MaxReceivedMessageSize, then we need to increase this quota.

No comments:

Post a Comment