user31673
user31673

Reputation: 13695

How to Configure WCF Service Application for 413 Request Entity Too Large Error

I have a WCF Service Application running that requires byte arrays to be sent to the service and be returned from the service. I am getting the 413 "Request Too Large" error. I have researched this error and there are many responses like changing the binding element to include maxReceivedMessageSize, adding the readerQuotes element to the binding element with settings and other changes. However, my web.config does not have the binding element. I changed it on the client side but this made no difference. It would make since that the server side (were the service runs) would be where these settings need to be done at. I am at a loss as to where I make the changes on the server side. What settings am I missing to take care of sending and receiving larger byte arrays? Here is the web.config the server is using:

<?xml version="1.0"?>
<configuration>

  <appSettings>
    <add key="aspnet:UseTaskFriendlySynchronizationContext" value="true" />
  </appSettings>
  <system.web>
    <compilation debug="true" targetFramework="4.5" />
    <httpRuntime targetFramework="4.5"/>
  </system.web>
  <system.serviceModel>
    <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="false"/>
        </behavior>
      </serviceBehaviors>
    </behaviors>
    <protocolMapping>
        <add binding="basicHttpsBinding" scheme="https" />
    </protocolMapping>    
    <serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" />
  </system.serviceModel>
  <system.webServer>
    <modules runAllManagedModulesForAllRequests="true"/>
    <!--
        To browse web app root directory during debugging, set the value below to true.
        Set to false before deployment to avoid disclosing web app folder information.
      -->
    <directoryBrowse enabled="true"/>
  </system.webServer>

</configuration>

Upvotes: 0

Views: 1262

Answers (2)

Tim
Tim

Reputation: 28530

Starting with WCF 4.0, by default (with no endpoints or bindings explicitly defined) WCF will create default endpoints with basicHttpBinding. This makes the configuration less cluttered, but also means you get the default values for the binding. There are two ways to resolve this when you need non-default settings for a binding (on the service side):

First, you can add a default binding configuration by ommitting the name attribute, like this:

<system.serviceModel>
  <bindings>
    <basicHttpBinding>
      <binding closeTimeout="........... />
    </basicHttpBinding>
  </bindings>

Or, you can name your binding configuration and then create an explicit endpoint that uses that configuration:

<system.serviceModel>
  <services>
    <service name=".....>
      <endpoint address="" bindingConfiguration="MyBasicHttpBinding"..... />

The second example assumes you have a binding configuration named "MyBasicHttpBinding" in your bindings section.

I've ommitted a good deal of the configuration for simplicity. Let me know if you need further details.

Upvotes: 1

Tacoman667
Tacoman667

Reputation: 1401

https://stackoverflow.com/a/884248/78551 is an accepted answer to this question. The server side will have a similar configuration set up.

I had this issue once due to trying to pull back huge datasets from entity framework. There is a limit and those kinds of things will HEAVILY affect how much data you can push through.

I broke my requests up. GetProducts, GetOrders, GetContracts, etc. Then on the client side I stitched them all together. I do NOT condone doing this but I was forced to handle such HUGE datasets by my architect.

Sometimes you just cannot get around the imposed limits of the framework/platform.

Also, have you looked at other protocols to use like net.tcp (if I recall correctly) that would open a socket and stream the data?

Upvotes: 0

Related Questions