Alterar a propriedade MaxArrayLength nas XmlDictionaryReaderQuotas objeto usado ao criar o leitor de XML

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

Pergunta

Estou recebendo a seguinte exceção ao enviar (ou receber) uma matriz de bytes para um serviço de 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

Para que eu possa entender o XmlDictionaryReader é criado automaticamente pelo webservice.

Então, como posso alterar a propriedade "MaxArrayLength"?

Este é o código de implementação:

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

Arquivos <16kb são carregados.

Arquivos> 16kb não são.

Arquivos> 10mb são baixados sem problema.

Onde é que a propriedade configurado?

Foi útil?

Solução

É um serviço WCF? Se assim for, você pode alterar o maxarraylength na ligação como se vê neste post SO:

pós

P.S. Por que você usaria um serviço personalizado Quando existem serviços OOTB do SharePoint que pode fazer upload de arquivos? ou seja, o Lists.asmx como neste artigo:

artigo

Outras dicas

Adicionar um elemento <readerQuotas> dentro do elemento <binding> e adicionar propriedade MaxArrayLength

 <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>
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top