Modifica della proprietà MaxArrayLength sull'oggetto XmlDictionaryReaderQuotas utilizzato durante la creazione del lettore XML
-
10-07-2019 - |
Domanda
Ricevo la seguente eccezione durante l'invio (o la ricezione) di un array di byte a un servizio 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
Per quello che posso capire, XmlDictionaryreader viene creato automaticamente dal servizio web.
Quindi, come posso cambiare " MaxArrayLength " proprietà?
Questo è il codice di implementazione:
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;
}
}
File < 16kb sono caricati.
File > 16kb non lo sono.
File > 10mb vengono scaricati senza problemi.
Dove è configurata quella proprietà?
Soluzione
È un servizio WCF? In tal caso, è possibile modificare la lunghezza massima della rilegatura come mostrato in questo post SO:
P.S. Perché dovresti usare un servizio personalizzato quando ci sono servizi OOTB Sharepoint che possono caricare file? cioè il Lists.asmx come in questo articolo:
Altri suggerimenti
Aggiungi un elemento <readerQuotas>
all'interno dell'elemento <binding>
e aggiungi MaxArrayLength
proprietà
<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>