I have a custom WCF service that external services are using to send generated documents through for storage in SharePoint.

Small files are working fine, but anything over 64KB is getting rejected with: (413) Request Entity too large.

Since I have used a factory in my svc, I have configured a feature and then in the Installed event for the feature I have put the following code:

SPWebService contentService = SPWebService.ContentService;
contentService.ClientRequestServiceSettings.MaxReceivedMessageSize = -1;

SPWcfServiceSettings settings = new SPWcfServiceSettings();

if (contentService.WcfServiceSettings.ContainsKey("dmsservice.svc"))
    settings = contentService.WcfServiceSettings["dmsservice.svc"];

settings.MaxReceivedMessageSize = Int32.MaxValue;
settings.MaxBufferSize = Int32.MaxValue;
settings.ReaderQuotasMaxStringContentLength = Int32.MaxValue;
settings.ReaderQuotasMaxArrayLength = Int32.MaxValue;
settings.ReaderQuotasMaxBytesPerRead = Int32.MaxValue;           

contentService.WcfServiceSettings["dmsservice.svc"] = settings;

However, even though all the posts i have found indicate that the above should work, it is not. So what am I missing in order to get this service to accept bigger files?

3 Answers 3


Heres the sample from the Blog:

Generate a class like this:

public class CustomMultipleBaseAddressWebServiceHostFactory : Microsoft.SharePoint.Client.Services.MultipleBaseAddressWebServiceHostFactory
        protected override System.ServiceModel.ServiceHost CreateServiceHost(Type serviceType, Uri[] baseAddresses)
            return new CustomMultipleBaseServiceHost(serviceType, baseAddresses);

    public class CustomMultipleBaseServiceHost : Microsoft.SharePoint.Client.Services.MultipleBaseAddressWebServiceHost
        public CustomMultipleBaseServiceHost(Type serviceType, params Uri[] baseAddresses)
            : base(serviceType, baseAddresses)

        protected override void OnOpening()

            foreach (ServiceEndpoint endpoint in this.Description.Endpoints)



        private static void IncreaseFileUploadSize(ServiceEndpoint endpoint) {
            var customBinding = endpoint.Binding as WebHttpBinding;
            if (customBinding != null)
              customBinding.MaxBufferSize = Int32.MaxValue;
              customBinding.MaxReceivedMessageSize = Int32.MaxValue;

And then use it in the yourservice.svc:

<%@ServiceHost Language="C#" Debug="true"
Service="NameSpaceOfMyService.MyServiceClassName, $SharePoint.Project.AssemblyFullName$"
Factory="NameSpaceOfMyServiceHostFactory.MyServiceHostFactoryClassName, $SharePoint.Project.AssemblyFullName$" %>

I have the same problem on SharePoint 2013. If I create a custom Service factory based on SharePoint factory and override config settings (MaxReceivedMessageSize) the error gone.

More info: http://cameron-verhelst.be/blog/2014/10/19/hosting-a-wcf-service-in-sharepoint-with-a-spcontext/

  • 2
    The link may contain the solution, but can you please add some brief description.
    – Asad Refai
    Commented Dec 1, 2015 at 11:30

If it will be useful to somebody. I do not quite understand where to put the code from the comment above. After I put it in a file "CodeBehind" everything worked fine. So, my cs looks like: enter image description here

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.