views:

710

answers:

2

To make a long story short:

  • Making a web application

  • Each user profile contains exactly one profile image, which is stored in the database

  • The bottom layer uses ADO.NET entity framework for data access and relationships between classes

  • Inserting images into the database on the bottom data access layer of the application works fine

  • On the top layer, in an MVC application, we use WCF to get the profile image to display. Displaying the image works fine no matter what the size, meaning that uploading images is the only problem.

  • In my Upload picture-function i can upload pictures up to 16k. Nothing bigger.

  • I have found all maxBufferSize and maxReceivedMessageSize properties in all app.config and web.config-files in the solution, and changed the values to 1MB (1 048 576)

This is the error i get:

The formatter threw an exception while trying to deserialize the message: There was an error while trying to deserialize parameter http://www.mydomain.com/contracts/profile/2009/07:userProfile. The InnerException message was 'There was an error deserializing the object of type Myproject.Commons.BusinessObjects.UserProfile. 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. Line 1, position 44978.'. Please see InnerException for more details.

It also tells me that the source file of the error is Reference.cs within the service reference. ...and now i basically cannot understand where this really comes from. Anyone has a clue?

+3  A: 

The error message says it all, really :-)

The maximum array length quota (16384) has been exceeded while reading XML data.

Besides all the maxBufferSize etc. settings, there's also a set of settings called ReaderQuotas which you can set when customizing a binding. One of those settings if the "maxArrayLength" which defaults to 16'384.

 <bindings>
    <wsHttpBinding>
       <binding name="Default" bypassProxyOnLocal="true"
                useDefaultWebProxy="true" >
           <readerQuotas maxArrayLength="16384"
                         maxBytesPerRead="4096" 
                         maxDepth="32"
                         maxNameTableCharCount="16384"
                         maxStringContentLength="8192"/>
       </binding>>
    </wsHttpBinding>
 </bindings>

These settings influence how the DataContractSerializer on the server will deserialize your message - you can look up details on the MSDN docs and set the values as you need them.

Marc

marc_s
I've set readerQUotas' maxArrayLength to 1048576 as well in my binding. However, I don't know what `wsHttpBinding` is. Mine are called `basicHttpBinding` and seems to contain basically the same that you wrote.
Arve Systad
wsHttpBinding is just the more "standards-compliant" version of basicHttpBinding - no problem at all. The setting works for basicHttpBinding just the same.
marc_s
Aah, okey. Hm, I've set all values to 1048576, no difference.
Arve Systad
OK - besides the maxBufferSize and maxReceivedMessageSize - did you also set the `maxBufferPoolSize` ? Is the error still the same?
marc_s
I've set every value possible to 1048576 :pCan post some more code tomorrow when i get back to work.
Arve Systad