Tutorial :Changing the MaxArrayLength property on the XmlDictionaryReaderQuotas object used when creating the XML reader



Question:

I'm getting the following exception while sending ( or receiving ) a byte array to a C# service.

There was an error deserializing the object of type System.Byte[].   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 6, position 34838.'.    Please see InnerException for more details  

For what I can understand the XmlDictionaryreader is created automatically by the webservice.

So, how can I change the "MaxArrayLength" property?

This is the implementation code:

    public string addFile(string sharePointServer, string documentLibrary,                             byte[] content, string fileName)       {          try          {              SPWeb spWeb = new SPSite(sharePointServer).OpenWeb();              SPFolder spFolder = spWeb.GetFolder(documentLibrary);              SPFileCollection spFileCollection = spFolder.Files;              SPFile spFile = spFileCollection.Add(fileName, content, true);              return spFile.TimeCreated.ToLongDateString() + "::" + spFile.Title;          }               catch (Exception ex)           {              throw ex;          }      }  

Files < 16kb are uploaded.

Files > 16kb are not.

Files > 10mb are downloaded without problem.

Where is that property configured?


Solution:1

Is it a WCF service? If so, you can change the maxarraylength in the binding as seen on this SO post:

post

P.S. Why would you use a custom Service when there are OOTB Sharepoint services that can upload files? i.e. the Lists.asmx like in this article:

article


Solution:2

Add a <readerQuotas> element inside the <binding> element and add MaxArrayLength property

 <bindings>       <wsHttpBinding>           <binding name ="Your WSHttpBinding Name" sendTimeout="00:05:00" maxReceivedMessageSize="2147483647">               <security mode="None"></security>               <readerQuotas maxStringContentLength="134217728" maxArrayLength="2147483647" />               <reliableSession enabled="true"/>           </binding>       </wsHttpBinding>   </bindings>  

Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Previous
Next Post »