Tuesday, June 25, 2013

How to change MaxReceivedMessageSize for Client Obejct Model in SharePoint 2010 2013

If you are using SharePoint client Object Model and you need to change max size of the message you need to pass to Client.svc, what you probably need is to increase the default value. This can occour for example if you are uploading files to a remote SharePoint using client object model.

The message you are receiving when executing query with client obejct model should be something similar to this: "The request message is too big. The server does not allow messages larger than 2097152 bytes."

The property is MaxReceivedMessageSize of ClientRequestServiceSettings.

Default value is 2MB (2097152 bytes).

Use this PowerShell script (from SharePoint Management Shell in Administrative mode with a Farm Administrative Account) to change this value.

In the example this is set to 2GB.

$ws = [Microsoft.SharePoint.Administration.SPWebService]::ContentService
$ws.ClientRequestServiceSettings.MaxReceivedMessageSize = 2147483647

Another option is to create a Farm Scoped Feature with this feature receiver:

public override void FeatureActivated(SPFeatureReceiverProperties properties)
   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 = 2147483647; // 2048MB
   contentService.WcfServiceSettings["client.svc"] = csomWcfSettings;


More at: http://msdn.microsoft.com/en-us/library/ff599489.aspx

No comments: