SharePoint 错误:服务器不允许大于 2097152 字节的消息 [英] SharePoint Error: The server does not allow messages larger than 2097152 bytes

查看:31
本文介绍了SharePoint 错误:服务器不允许大于 2097152 字节的消息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有指向 sharepoint 2013 Office 365 的 Web 服务.我使用客户端对象模型.我正在尝试更新其中存储 4 个附件的 xml 文件.当我在 xml 文件中有大量二进制数据时执行此操作时,我收到以下错误:

I have web service that point to sharepoint 2013 Office 365. I use the client object model. I am trying to update the xml file which stores 4 attachments in it. When I do this when I have large binary data in the xml file I get the following error :

留言

请求消息太大.服务器不允许发消息大于 2097152 字节.

The request message is too big. The server does not allow messages larger than 2097152 bytes.

我意识到我可能不得不将附件与 xml 文件分开,但目前我的 infopath 表单将它们存储在那里.有没有办法可以增加请求长度,或者可以分块保存或其他东西.我真的只是修改了一个节点,除非我更新 xml,否则它不会工作.谢谢 .代码如下.

I realize I am probably going to have to seperate the attachments from the xml file but currently my infopath form stores them there. Is there a way I can increase the request length or maybe chunk up saving or something. I really just modifying one node and it won't work unless I update the xml. Thanks . Code Below.

我的代码:

ListItem docReq = GetDocRequestLight(docRequestID, businessID);
string fPath = (string)docReq["FileRef"];
using (FileInformation fInfo = Microsoft.SharePoint.Client.File.OpenBinaryDirect(ctx, fPath))
{
    XmlDocument xmlDoc = new XmlDocument();
    xmlDoc.Load(fInfo.Stream);
    XmlNamespaceManager xmlNameSpaceMgr = new XmlNamespaceManager(xmlDoc.NameTable);
    xmlNameSpaceMgr.AddNamespace("my", DocReqXmlNameSpace);

    // Get Parent Node
    XmlNode node = xmlDoc.SelectSingleNode(GetXPathFromItemKey(velmaKey), xmlNameSpaceMgr);

    DateTime outDate;
    bool outBool;
    if (DateTime.TryParse(newValue, out outDate))
        node.InnerText = outDate.ToString("yyyy-MM-dd");
    if (Boolean.TryParse(newValue, out outBool))
        node.InnerText = newValue;

    // Update Statuses
    XmlNode statusIDNode = xmlDoc.SelectSingleNode(DocReqStatusIDFieldXPath, xmlNameSpaceMgr);
    statusIDNode.InnerText = updatedStatus.ID.ToString();
    XmlNode statusNode = xmlDoc.SelectSingleNode(DocReqStatusFieldXPath, xmlNameSpaceMgr);
    statusNode.InnerText = updatedStatus.Name.ToString();

    // Save File
    docReq.File.SaveBinary(new FileSaveBinaryInformation()
    {
        Content =   Encoding.UTF8.GetBytes(xmlDoc.OuterXml),
    });

    ctx.ExecuteQuery();

推荐答案

SharePoint 对 CSOM 有自己的限制.遗憾的是,这些限制无法在管理中心配置,也无法使用 CSOM 设置,原因很明显.

SharePoint has its own limits for CSOM. Unfortunately, these limits cannot be configured in Central Administration and also cannot be set using CSOM for obvious reasons.

在 Google 上搜索该问题时,通常通过将 ClientRequestServiceSettings.MaxReceivedMessageSize 属性设置为所需大小来提供解决方案.

When googling for the issue, mostly a solution is given by setting the ClientRequestServiceSettings.MaxReceivedMessageSize property to the desired size.

从 SharePoint Management Shell 调用以下 PowerShell 脚本:

Call the following PowerShell script from SharePoint Management Shell :

$ws = [Microsoft.SharePoint.Administration.SPWebService]::ContentService 
$ws.ClientRequestServiceSettings.MaxReceivedMessageSize = 209715200 
$ws.Update()

这会将限制设置为 200 MB.

This will set the limit to 200 MB.

但是,在 SharePoint 2013 中,Microsoft 显然添加了另一个配置设置,以限制服务器应从 CSOM 请求中处理的数据量(为什么有人会以不同的方式配置此设置超出我的范围...)在阅读了一个非常长的 SharePoint 日志文件并抓取了一些反汇编的 SharePoint 服务器代码后,我发现可以通过属性 ClientRequestServiceSettings.MaxParseMessageSize 设置此参数.

However, in SharePoint 2013 Microsoft apparently added another configuration setting to also limit the amount of data which the server shall process from a CSOM request (Why anyone would configure this one differently is beyond me...). After reading a very, very long SharePoint Log file and crawling through some disassembled SharePoint server code, I found that this parameter can be set via the property ClientRequestServiceSettings.MaxParseMessageSize.

我们现在在 SharePoint 2013 中使用以下脚本并且效果很好:

We are now using the following script with SharePoint 2013 and it works great:

$ws = [Microsoft.SharePoint.Administration.SPWebService]::ContentService 
$ws.ClientRequestServiceSettings.MaxReceivedMessageSize = 209715200 
$ws.ClientRequestServiceSettings.MaxParseMessageSize = 209715200 
$ws.Update()  

希望能让一些人免于头疼!

Hope that saves some people a headache!

这篇关于SharePoint 错误:服务器不允许大于 2097152 字节的消息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆