views:

945

answers:

1

I have a data service that takes a byte array. I then have a web page that attempts to send a file to that data service. If the file is small (say 50kb) then everything functions as expected, however if the file is large (anything over 100kb) I get a "BadRequest" error message on the save change call for the data service.

Is there a way to enable larger data sizes to be passed to the data service?

EDIT (more details): I've set maxRequestLength higher and tried some webHttpBinding to increase maxReceivedMessageSize, but these do not seem to be helping.

+3  A: 

The maximum size of the request which a WCF service can process is controlled by the MaxReceivedMessageSize property on the WCF binding. The default value is 65536 ,exceeding which you get the 400 response code.

In the web.config of the web site hosting the service , add the following node in the section.

<system.serviceModel> 
<services> 
  <!-- The name of the service --> 
  <service name="NorthwindService"> 
    <!-- you can leave the address blank or specify your end point URI --> 
    <endpoint address ="YourServiceEndpoint" 
              binding="webHttpBinding" bindingConfiguration="higherMessageSize" 
     contract ="System.Data.Services.IRequestHandler"> 
    </endpoint> 
  </service> 
</services> 
<bindings> 
  <webHttpBinding> 
    <!-- configure the maxReceivedMessageSize  value to suit the max size of 
         the request ( in bytes ) you want the service to recieve--> 
    <binding name="higherMessageSize" maxReceivedMessageSize ="MaxMessageSize"/> 
  </webHttpBinding> 
</bindings> 
<serviceHostingEnvironment aspNetCompatibilityEnabled="true"/> 
</system.serviceModel>

If hosted on IIS , the ASP.Net Request Size restriction can also cause a large request to be rejected, You will need to set the HttpRuntimeSection.MaxRequestLength Property.

<system.web> 
  <httpRuntime MaxRequestLength="ValueInKiloBytes" />
</system.web>

Identify if WCF is throwing an exception under the covers which is not being surfaced to you at the HTTP level. You can configure WCF tracing on the server-side to log the necessary information from the WCF layer. Once you have tracing setup and you reproduced the failure , check if the log contains one or both of these exception messages.

System.ServiceModel.ProtocolException
"The maximum message size quota for incoming messages (65536) has been exceeded. 
To increase the quota, use the MaxReceivedMessageSize property on the appropriate binding element."

System.Web.HttpException
"Maximum request length exceeded."

If you see that the log does contain this message , then you can be sure that the failure is because of the message size and apply this fix accordingly.

PD: Remember that your form must use the "POST" method.

mapache