Modification de la propriété MaxArrayLength sur l'objet XmlDictionaryReaderQuotas utilisé lors de la création du lecteur XML

StackOverflow https://stackoverflow.com/questions/1035600

Question

Je reçois l'exception suivante lors de l'envoi (ou de la réception) d'un tableau d'octets vers un service C #.

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

Pour ce que je peux comprendre, XmlDictionaryreader est créé automatiquement par le service Web.

Alors, comment puis-je changer le " MaxArrayLength " propriété?

Ceci est le code d'implémentation:

    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;
        }
    }

Fichiers < 16kb sont téléchargés.

Fichiers > 16kb ne sont pas.

Fichiers > 10mb sont téléchargés sans problème.

Où cette propriété est-elle configurée?

Était-ce utile?

La solution

Est-ce un service WCF? Si tel est le cas, vous pouvez modifier la longueur maximale dans la liaison, comme indiqué sur ce message SO:

poster

P.S. Pourquoi voudriez-vous utiliser un service personnalisé alors que des services OOTB Sharepoint peuvent télécharger des fichiers? c'est-à-dire les listes.asmx comme dans cet article:

article

Autres conseils

Ajouter un élément <readerQuotas> à l'intérieur de l'élément <binding> et ajouter une MaxArrayLength propriété

 <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>
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top