1

I know the "HTTP 413 Request Entity too large" error is a FAQ. But I have a variation that I've been unable to figure out for two days now. I've created a WCF service endpoint as part of an on-prem SharePoint 2013 application (see below). The web site is SSL enabled and I'm getting the 413 error. I've tried increasing maxReceivedMessageSize in the site web.config per the many posts related to this error as well as modifying the flag on the site itself via IIS Manager / Site / Management / Configuration Editor. But nothing seems to work. I can post small files with no problem. My guess is that maybe SharePoint does something to override the binding and that I need to apply the maxReceivedMessageSize change in a different place

Service contract

[ServiceContract]
public interface ISharepointService
{

    [OperationContract]   
    [WebInvoke(Method = "POST", UriTemplate = "UploadFile?partner={partnerid}&location={locationid}&filename={filename}&type={type}&period={period}")]   
    void UploadFile(string partnerid, string locationid, string filename, string type, string period, Stream stream);*

web.config

<services>
  <service behaviorConfiguration="serviceBehavior" name="MyCompany.Sharepoint.MyService.SharepointServiceApp">
    <endpoint address="Sharepoint" behaviorConfiguration="webBehavior" binding="webHttpBinding" bindingConfiguration="webBinding" contract="MyCompany.Sharepoint.MyService.SharepointServiceApp"></endpoint>
    <endpoint address="mex" binding="mexHttpsBinding" contract="IMetadataExchange" />
  </service>
</services>
<bindings>
  <webHttpBinding>
    <binding name="webBinding" maxReceivedMessageSize="2147483647">
      <security mode="Transport">
      </security>        
    </binding>
  </webHttpBinding>
</bindings>
Tim
  • 28,212
  • 8
  • 63
  • 76

3 Answers3

3

I was able to resolve this by creating/modifying the binding for my service in SharePoint. I did this by executing the following powershell script:

$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)

This effectively did as suggested by the original responder. But it fixed the problem for the special case scenario where the web service is part of a SP application.

0

There's more configurations that must be set, try to set this:

<system.web>
    <httpRuntime maxRequestLength="2147483647" />
</system.web>

And add this to your binding:

<webHttpBinding>
    <binding name="webBinding" maxReceivedMessageSize="2147483647" maxBufferPoolSize="2147483647" maxBufferSize="2147483647">
       <readerQuotas maxStringContentLength="2147483647" maxArrayLength="2147483647" maxBytesPerRead="2147483647" />
       <security mode="Transport"></security>        
    </binding>
</webHttpBinding>
Ricardo Pontual
  • 3,749
  • 3
  • 28
  • 43
  • Unfortunately, that didn't work for me. Since I've seen this fix discussed extensively, I'm wondering if this is specific to SharePoint and maybe I'm just not making the change in the right place. I have a VS Project with the Service defined that generates a SharePoint WSP. I've set it in the app.config under my project – SylverSmyth Oct 12 '16 at 17:19
  • I can see the changes are applied in the bin/project.dll.config file. But I don't really understand what happens to the config when the WSP gets deployed to a SharePoint web app. Is it possibly embedded somewhere in the site contents? And if so, how do I validate that the binding change is being applied correctly? – SylverSmyth Oct 12 '16 at 17:22
0

SylverSmyth's soultion worked for me.
Without creating Service Factory.
Only one note: name of a service in ["<my service name>.svc"] should be in lowercase.

SLCH000
  • 1,821
  • 2
  • 14
  • 15