4

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;
contentService.Update(true);

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?

4

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()
        {
            base.OnOpening();

            foreach (ServiceEndpoint endpoint in this.Description.Endpoints)
            {

                IncreaseFileUploadSize(endpoint);

            }
        }

        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$" %>
3

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 Dec 1 '15 at 11:30
0

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, privacy policy and cookie policy

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