0

I created a simple WCF rest endpoint and deployed it to Sharepoint - 80 running under IIS.

The service accepts a post request with JSON content. It works fine when the post request's content does not exceed 65536 bytes. For any larger posts the server responds with a

413 request entity too large

64k seems to be the default upload limit in IIS. To increase the limit, I want to add a web.config and set the maxReceivedMessageSize parameter.

However, when I add the following web.config into the home directory of the service:

<?xml version="1.0"?>
<configuration>
  <system.serviceModel>
    <bindings>
        <webHttpBinding>
           <binding name="ExtendedMaxSize"  
               maxBufferSize="999999" maxReceivedMessageSize="999999" />
        </webHttpBinding>
    </bindings>
    <services>
      <service name="SharePointProject1.Service1" behaviorConfiguration="">
        <endpoint address="http://localhost/_vti_Bin/testproject/sharepointproject1.svc"
                  binding="webHttpBinding"
                  bindingConfiguration="ExtendedMaxSize"  
                  contract="SharePointProject1.IService1" />
      </service>
    </services>
  </system.serviceModel>
</configuration>

the service stops running and throws the error

A registration already exists for http://localhost/_vti_Bin/testproject/sharepointproject1.svc

How can I change the service configuration to increase the upload limit?

PS: I have researched SO extensively and found numerous links all pointing to changing the settings in web.config. I tried changing the standard Sharepoint web.config which did not have any effect on my service.

matt
  • 90
  • 1
  • 8

2 Answers2

0

Please check your client config to make sure the binding config has the same properties: maxReceivedMessageSize="2147483647"

Increase MaxReceivedMessageSize value for your web service to solve this issue. However, this may get tricky because there are two different MaxReceivedMessageSize parameters:

MaxReceivedMessageSize in System.ServiceModel.Configuration.BasicHttpBindingElement

MaxReceivedMessageSize in System.ServiceModel.Channels.HttpTransportBindingElement

This configuration below will increase the MaxReceivedMessageSize in System.ServiceModel.Configuration.BasicHttpBindingElement:

<basicHttpBinding>
   <binding name="basicHttpBinding_Portal" > maxReceivedMessageSize="2147483647" maxBufferSize="2147483647" > maxBufferPoolSize="2147483647">
       <readerQuotas maxBytesPerRead="2147483647" > maxArrayLength="2147483647" maxStringContentLength="2147483647" > maxDepth="2147483647" maxNameTableCharCount="2147483647"/>
    </binding>
</basicHttpBinding>

You should increase the MaxReceivedMessageSize in System.ServiceModel.Channels.HttpTransportBindingElement as well:

<customBinding>
   <binding closeTimeout="00:10:00" openTimeout="00:10:00" > sendTimeout="00:10:00">
      <httpTransport maxReceivedMessageSize="2147483647" > maxBufferSize="2147483647" useDefaultWebProxy="true" > transferMode="Buffered" />
   </binding>
</customBinding>

The above content comes from this blog: WCF service doesn’t accept files over 64 KB.

YurongDai
  • 1,362
  • 1
  • 2
  • 7
0

In case someone else faces the same problem: I had tried to manually edit the config files in different places, including the service and the Sharepoint site, adding the bindings, and increasing the limits as suggested. But nothing worked. What did work in the end was setting the limits via Powershell:

$contentService = [Microsoft.SharePoint.Administration.SPWebService]::ContentService;
$contentService.ClientRequestServiceSettings.MaxReceivedMessageSize = -1
$wcfServiceSettings = New-Object Microsoft.SharePoint.Administration.SPWcfServiceSettings
$wcfServiceSettings.ReaderQuotasMaxStringContentLength = 2147483647
$wcfServiceSettings.ReaderQuotasMaxArrayLength = 2147483647
$wcfServiceSettings.ReaderQuotasMaxBytesPerRead = 2147483647
$wcfServiceSettings.MaxReceivedMessageSize = 2147483647
$wcfServiceSettings.MaxBufferSize = 2147483647
$wcfServiceSettings.ReaderQuotasMaxDepth = 2147483647
$wcfServiceSettings.ReaderQuotasMaxNameTableCharCount = 2147483647
$contentService.WcfServiceSettings["<my service name>.svc"] = $wcfServiceSettings
$contentService.Update($true)

I found the answer in this post: HTTP 413 error posting to SharePoint web service

matt
  • 90
  • 1
  • 8