Handling Large Data with SharePoint 2010 Custom WCF Service

October 16, 2014

Calling your custom WCF web service successfully with a small, known and fixed amount of test data only to have it fail with large and variable real world data? You can follow these steps to try and track down the issue. However, if you continue to get a 400 Bad Request error, you might be exceeding the maximum message size quota. The solution is to increase this limit as follows:

SPWebService contentService = SPWebService.ContentService;
SPWcfServiceSettings wcfServiceSettings = new SPWcfServiceSettings();
wcfServiceSettings.ReaderQuotasMaxStringContentLength = Int32.MaxValue;
wcfServiceSettings.ReaderQuotasMaxArrayLength = Int32.MaxValue;
wcfServiceSettings.ReaderQuotasMaxBytesPerRead = Int32.MaxValue;
wcfServiceSettings.MaxReceivedMessageSize = Int32.MaxValue;
wcfServiceSettings.MaxBufferSize = Int32.MaxValue;
wcfServiceSettings.ReaderQuotasMaxDepth = Int32.MaxValue;
wcfServiceSettings.ReaderQuotasMaxNameTableCharCount = Int32.MaxValue;
wcfServiceSettings.ReceiveTimeout = TimeSpan.MaxValue;

contentService.WcfServiceSettings["your_custom_service.svc"] = wcfServiceSettings;
contentService.Update();