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?