4

I have following WCF service hosted in SharePoint:

[ServiceContract]
public interface IPrintService
{
  [OperationContract]
  [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"
               Service="..."
               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?

1
  • 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, 2013 at 12:55

1 Answer 1

3

This blog post may help: http://www.sharepoint.bg/radi/post/Custom-WCF-Services-and-setting-Reader-Quotas-in-SharePoint-2010.aspx

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;

contentService.Update(true);
3
  • 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, 2013 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 Mar 28, 2013 at 15:17
  • Dead link. WebArchive version : web.archive.org/web/20160121030402/http://www.sharepoint.bg/…
    – Steve B
    Jan 26, 2018 at 8:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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