Wednesday, 7 March 2007

WCF - Handling large data sizes

WCF is a bit fussy when it comes to protecting you against denial of service attacks by sending large data packets. This is great when you don't need to send large amounts of data, but when you do, it can cause you a few problems.

I've come across a situation recently sending multi megabyte attachments through a WCF service. In its default state WCF won't accept large data transmissions, you have to specifically configure it to accept large data by changing the binding as follows:

<binding name="AuthBinding" maxReceivedMessageSize="100000">

As the name implies maxReceivedMessageSize tells WCF how big a message it will be allowed to receive. If you're sending a large byte array across the wire - maybe an attachment file or something - you need to also configure the XmlReader that WCF uses to tell it how big an array to accept. You do this through the use of the readerquotas declaration within your binding:

<readerquotas maxArrayLength="10485760" />

This would allow the XmlReader to accept a byte array equivalent to a 10mb file.

No comments:

Post a comment