0

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>
user31673
  • 13,245
  • 12
  • 58
  • 96

2 Answers2

1

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.

Tim
  • 28,212
  • 8
  • 63
  • 76
0

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?

Community
  • 1
  • 1
Tacoman667
  • 1,391
  • 9
  • 16
  • My question is about how to configure the service. My data is not very big and should be fine to use the byte arrays. I just don't have it configured right. – user31673 Jun 20 '14 at 21:35
  • You might think it's not very big but the models being serialized for transport are doing it in xml format thus adding LARGE amounts of bytes to the package. – Tacoman667 Jun 20 '14 at 21:36
  • People have been able to get his working just fine. My question is about the configuration. I don't see how the server side can be configured. That is what I am missing. – user31673 Jun 20 '14 at 21:38
  • You edited your response to link to an answer. I have already looked at that answer and this is my confusion. I don't see where I add the settings to the web.config on the server. Doesn't the server side need the changes and not the client? – user31673 Jun 20 '14 at 22:01
  • They both need them set. The client should update when you right click the server reference in VS and select update service or whatever it's called. On the server side it's in the web/app.config file. – Tacoman667 Jun 20 '14 at 22:43