Large Files in WCF Service

410 Views Asked by At

I have a WCF SOAP service and I am trying to submit a file to the service that is too large (128KB). I have scoured the internet and found many suggestions about adding the maxReceivedMessageSize, maxBufferSize, and other such attributes, but to no avail. I have also added the maxRequestLength to the httpRuntime but that doesn't work either. Not matter what I do I keep getting HTTP Error 413: Request Entity Too Large.

Error

HTTP Error 413: Request Entity Too Large.

Web Config

<httpRuntime targetFramework="4.5.1" maxRequestLength="1048576"/>

<system.serviceModel>
    <bindings>
      <basicHttpBinding>
        <binding name="SomeBinding" maxBufferPoolSize="2147483647" maxReceivedMessageSize="2147483647" maxBufferSize="2147483647" openTimeout="00:20:00"
          receiveTimeout="00:20:00" closeTimeout="00:20:00" sendTimeout="00:20:00">
          <readerQuotas maxDepth="200" maxStringContentLength="8388608" maxArrayLength="16384" maxBytesPerRead="2147483647" maxNameTableCharCount="16384" />
        </binding>
      </basicHttpBinding>
    </bindings>
 <behaviors>
      <serviceBehaviors>
        <behavior>
          <!-- To avoid disclosing metadata information, set the values below to false before deployment -->
          <serviceMetadata httpGetEnabled="true" httpsGetEnabled="true"/>
          <!-- To receive exception details in faults for debugging purposes, set the value below to true.  Set to false before deployment to avoid disclosing exception information -->
          <serviceDebug includeExceptionDetailInFaults="true"/>
        </behavior>
      </serviceBehaviors>
    </behaviors>
    <protocolMapping>
      <add binding="basicHttpsBinding" scheme="https" />
    </protocolMapping>
    <serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" />
  </system.serviceModel>
2

There are 2 best solutions below

0
On

Even though you've set larger quotas in your binding, that binding is not being used by your service because it's never assigned to an endpoint or set as the default binding for basicHttpBinding.

Since you don't have an explicit endpoint defined in your config file, you can set your binding configuration as the default for basicHttpBinding by omitting the name attribute, like this:

<binding maxBufferPoolSize="2147483647" 
         maxReceivedMessageSize="2147483647" 
         maxBufferSize="2147483647" 
         openTimeout="00:20:00"
         receiveTimeout="00:20:00" 
         closeTimeout="00:20:00" 
         sendTimeout="00:20:00">
  <readerQuotas maxDepth="200" 
                maxStringContentLength="8388608" 
                maxArrayLength="16384" 
                maxBytesPerRead="2147483647" 
                maxNameTableCharCount="16384" />
</binding>

Without making it the default for all requests that use basicHttpBinding (or assigning it to an explicit endpoint), the service will create the binding with the default (and smaller) values.

For more information on default bindings (and endpoints and behaviors), see A Developer's Introduction to Windows Communication Foundation 4.

0
On

@Tim I have seen this in several spots online and it is correct, except that you are missing something else. I was getting confused since I am new to WCF and my service wraps another service so that I can perform new logic without changing the existing system. Therefore any changes I was making were only getting applied to the client I am calling into. You need to add the below <services> to the <system.serviceModel> in order for those changes to be applied to the service.

<services>
      <service name="ANX.DEX001.WebService.EtPrintService">
        <endpoint name="basicHttpBinding"
                  address="/EtPrintService.svc"
                  binding="basicHttpBinding"
                  contract="ANX.DEX001.WebService.IEtPrintService"
                  bindingConfiguration="APIPortBinding"/>
      </service>
</services>