3

在向 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

据我所知,XmlDictionaryreader 是由 web 服务自动创建的。

那么,如何更改“MaxArrayLength”属性?

这是实现代码:

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

上传小于 16kb 的文件。

> 16kb 的文件不是。

> 10mb 的文件下载没有问题。

该属性在哪里配置?

4

2 回答 2

7

它是 WCF 服务吗?如果是这样,您可以更改绑定中的 maxarraylength,如此 SO 帖子所示:

邮政

PS当有可以上传文件的 OOTB Sharepoint 服务时,为什么要使用自定义服务?即本文中的 Lists.asmx:

文章

于 2009-06-24T05:56:16.973 回答
1

<readerQuotas>在元素内添加<binding>元素并添加 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>
于 2017-01-09T13:22:46.083 回答