【问题标题】:SP2010 Client Object Model 3 MB limit - updating maxReceivedMessageSize doesnt get appliedSP2010 客户端对象模型 3 MB 限制 - 未应用更新 maxReceivedMessageSize
【发布时间】:2011-11-27 20:46:14
【问题描述】:

我正在使用客户端对象模型与 Sharepoint 2010 进行交互。当我尝试使用客户端 OM 上传大于 3 MB 的文档时,它给出了错误错误请求。微软建议this 解决这个问题。我尝试过并更新了 maxReceivedMessageSize 属性。我重新启动系统后它工作正常,但没有应用于正在运行的共享点服务器。

我认为由于设置可能已保存在内存中,因此需要重置应用程序,但我不知道要重置什么。我尝试过重置不同的 Sharepoint 服务。我曾尝试在 IIS 中重置 Sharepoint 网站。没有任何帮助。

另外,例如,如果我设置了 10 MB 的限制,我可以上传大约 7.5 MB 的文档。我认为这是因为额外的元数据(内容类型属性等)。这是正确的行为还是我还需要更改其他内容。

不胜感激。

问候。

【问题讨论】:

  • 我怀疑每个有效负载都有 25% 的元数据开销。这是不可接受的。

标签: c# sharepoint settings sharepoint-clientobject


【解决方案1】:

我找到了this TechNet Forum entry,它帮助我解决了这个问题:

按照以下步骤告诉 SharePoint 增加其文件大小。
Ø 作为 SharePoint 站点管理员,通过
访问 SharePoint 2010 Management Shell 1. 在开始菜单上,单击所有程序。
2. 单击 Microsoft SharePoint 2010 产品。
3. 单击 SharePoint 2010 命令行管理程序。
Ø 然后运行下面的命令。

get-PSSnapin - Registered
Add-PSSnapin Microsoft.SharePoint.Powershell
$ws = [Microsoft.SharePoint.Administration.SPWebService]::ContentService
$ws.ClientRequestServiceSettings.MaxReceivedMessageSize = 2147483647
$ws.Update()

告诉 Asp.Net 按照以下步骤增加文件大小。
Ø 编辑所有涉及的web.config文件添加元素''。
完成后,您的添加应如下例所示。
Ø 2147483647 字节等于 1.99 GB。
<system.web>
<httpRuntime useFullyQualifiedRedirectUrl="true" maxRequestLength="2147483647" requestLengthDiskThreshold="2147483647" executionTimeout="18000"/> </system.web>

按照以下步骤告诉 IIS 7.0 及更高版本增加其文件大小。
编辑所有涉及的 web.config 文件以添加元素“”。
完成后,您的添加应如下例所示。
<system.webServer>
<modules runAllManagedModulesForAllRequests="true"/>
<security>
<requestFiltering>
<requestLimits maxAllowedContentLength="2147483647" />
</requestFiltering>
</security>
</system.webServer>

我希望这会有所帮助!

【讨论】:

    【解决方案2】:

    这不是 SharePoint 的问题或硬限制。这是为保护 SharePoint 基础结构而设置的操作上传限制。操作上传限制为 2 MB,而二进制上传限制为 50 MB。

    目前有3种方法:

    1. 正如您已经提到的,增加 maxReceivedMessageSize。

    2. 使用SaveBinaryDirect 方法

      这些方法是从 SharePoint 2010 开始引入的。它基本上使用分布式创作版本控制 (DAV) 来发出 PUT 请求。使用这种方法,您有 50 MB 的二进制上传限制。

      这是方法 #2 的示例实现,

      string siteURL = "https://records.contoso.com";
      
      using (var context = new Microsoft.SharePoint.Client.ClientContext(siteURL))
      {
         context.Credentials = new NetworkCredential(
            "username", 
            "password", 
            "domain");
         string filePathToUpload = "C:\test\test.txt";
         context.ExecuteQuery();
      
         using (FileStream fs = new FileStream(filePathToUpload, FileMode.Open)
         {
            string targetURL = "/testsite/test.txt";
            Microsoft.SharePoint.Client.File.SaveBinaryDirect(
               context, 
               targetURL, 
               fs, 
               true);
         }
      }
      
    3. 如果您使用的是 SharePoint 2013 或更高版本,则可以使用 REST API。上传限制为 2 GB。

    【讨论】:

      【解决方案3】:

      根据您发送的链接,获取所需内容的正确方法应该是这样的:

      public static void IncreaseMaxReceivedMessageSize ()
      {
          SPWebService contentService = SPWebService.ContentService;
      
          /* Must set this to -1, else, the MaxReceivedMessageSize value for
          SPWebService.ContentService.WcfServiceSettings["client.svc"] will not be used.*/
          contentService.ClientRequestServiceSettings.MaxReceivedMessageSize = -1;
      
          // SPWcfServiceSettings has other Properties that you can set.
          SPWcfServiceSettings csomWcfSettings = new SPWcfServiceSettings();
          csomWcfSettings.MaxReceivedMessageSize = 10485760; // 10MB
          contentService.WcfServiceSettings["client.svc"] = csomWcfSettings;
      
          contentService.Update();
      }
      

      请通过编辑您的问题来显示您的代码,并说明您重新启动哪个系统然后它可以工作,而不是重新启动或回收您声称它不起作用的 SP 站点...

      【讨论】:

      • 感谢您的回复大卫。我刚刚将相同的代码从 Microsoft 链接复制到我在服务器上运行的 consol-application 中。通过重新启动系统,我的意思是,我重新启动了机器,然后它就可以工作了。我知道这是 Sharepoint Client OM 的 WCF 设置,但我不明白它的位置或如何重置它。
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多