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

半城伤御伤魂 提交于 2020-01-01 06:52:14

问题


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?


回答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




回答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>


来源:https://stackoverflow.com/questions/1035600/changing-the-maxarraylength-property-on-the-xmldictionaryreaderquotas-object-use

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!