SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have following WCF service hosted in SharePoint:

public interface IPrintService
  [WebInvoke(Method = "POST", RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json, UriTemplate = "/Print", BodyStyle = WebMessageBodyStyle.Wrapped)]
  string Print(PrintMessage message);

The service host definition looks like:

<%@ServiceHost Language="C#" Debug="true"
               Factory="Microsoft.SharePoint.Client.Services.MultipleBaseAddressWebServiceHostFactory, ..." %>

Everything looks right and works fine. I can post an AJAX message from the client with jQuery. But when the post data's size is huge I get bad request error (400). The MaxReceivedMessageSize for WCF has to be changed to a higher value I think.

I found this blog. So I opened PowerShell, got the web application, called the WebService property on it. Only listdata.svc service was listed in WcfServiceSettings.

I have created a new SPWcfServiceSettings object $wss, changed the size properties, and added it into the list: $ws.WcfServiceSettings.Add('printservice.svc', $wss); $ws.Update().

The result is that I still get error 400.

What I am doing wrong? Is there a way to change that value on the fly? Maybe by inheriting from MultipleBaseAddressWebServiceHostFactory and doing some extra work?

share|improve this question
Problem has nothing to do with data size. Problem was building a JSON object with real world data. Real world data have quotation marks. – Yavuz Mar 28 '13 at 12:55

This blog post may help:

The following code will set all the quotas to their max value. If you are still getting errors with that quota then you are likely trying to send too much info in one call and its time to split it into multiples.

SPWebService contentService = SPWebService.ContentService;

contentService.ClientRequestServiceSettings.MaxReceivedMessageSize = -1;

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["MyService.svc"] = wcfServiceSettings;

share|improve this answer
Thank you Ryan. Further investigation has shown that the problem had nothing to do with data size. It was a problem stringifying JSON object which has quotation marks. Problem came out with real data testing. – Yavuz Mar 28 '13 at 12:53
Im glad you found a solution, can you please add it and mark it as the answer for anyone that may have a similar problem in the future – Ryan Erickson Mar 28 '13 at 15:17

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.