Note that there are some explanatory texts on larger screens.

plurals
  1. POjquery return error 400 when POSTing large data to wcf web service
    primarykey
    data
    text
    <p>I call my WCF Web service using JQuery .AJAX and pass a collection of items to process. The majority of the time it works fine, but when I have a large number of items in the collection when I POST I immediately get an Error 400.</p> <p>Here is the jQuery code :</p> <pre><code> // Get the selected items var oAssayOrderListSelected = jQuery.grep(oAssayOrderList, function (element, index) { return element.SelectedForProcessing == true; }); DataAsJson = { "SelectedItems": oAssayOrderListSelected }; var DataAsJsonString = JSON.stringify(DataAsJson); // Call the web service to Process the Assays $.ajax({ cache: false, url: "AssayControlWS.svc/ProcessOrdersForAssays", type: "POST", async: true, dataType: "json", data: DataAsJsonString, contentType: "application/json; charset=utf-8", success: function (processingResults) { // Update the results table with the result information if (processingResults.Status == "Success") { } else { // insert error message handler!!!!! } }, </code></pre> <p>Here is the declaration of the web service method being called:</p> <pre><code>[WebInvoke(Method = "POST", BodyStyle = WebMessageBodyStyle.WrappedRequest, ResponseFormat = WebMessageFormat.Json, RequestFormat = WebMessageFormat.Json)] public ReleaseResult ProcessOrdersForAssays(List&lt;AssayGroupOrOrderSummary&gt; SelectedItems) { ... } </code></pre> <p>Here is the web.config entries for the service. As it shows I have increased the buffer sizes greatly from the defaults</p> <pre><code> &lt;service name="AssayControl_Web.AssayControlWS" behaviorConfiguration="metadataAndDebug"&gt; &lt;endpoint address="" behaviorConfiguration="AssayControl_Web.AssayControlWSAspNetAjaxBehavior" binding="webHttpBinding" contract="AssayControl_Web.AssayControlWS" bindingName="AssayControl_Web.AssayControlWS" /&gt; &lt;/service&gt; &lt;behaviors&gt; &lt;endpointBehaviors&gt; &lt;serviceBehaviors&gt; &lt;behavior name="metadataAndDebug"&gt; &lt;serviceMetadata httpGetEnabled="true" httpGetUrl=""/&gt; &lt;serviceDebug httpHelpPageEnabled="true" includeExceptionDetailInFaults="true" /&gt; &lt;/behavior&gt; &lt;/serviceBehaviors&gt; &lt;/endpointBehaviors&gt; &lt;/behaviors&gt; &lt;webHttpBinding&gt; &lt;binding name="AssayControl_Web.AssayControlWS" maxBufferSize="200000000" maxBufferPoolSize="200000000" maxReceivedMessageSize="200000000" transferMode="Buffered" /&gt; &lt;/webHttpBinding&gt; </code></pre> <p>Any thoughts on what is causing this 400 error?</p> <p>=================== Problem solved ===============================</p> <p>After adding WCF logging I was able to see that the issue was that the web service was using the default value of 65536 for the maxReceivedMessageSize. This was in spite of my setting this value to a much higher value. </p> <p>Additionally searching showed that several other people had encountered the issue of the maxReceivedMessageSize being ignored. The way I fixed the problem was to remove the Name property from the webHttpBinding, making that setting the default for all webHttpBinding. Then remove the BindingName property from service Endpoint so it used the default binding. </p> <p>Here is a link to other reports of this problem with the same fix, <a href="http://social.msdn.microsoft.com/Forums/vstudio/en-US/985e039f-1610-4f62-9c3d-51ec7e1b1673/problem-with-maxreceivedmessagesize-webconfig-ignored" rel="nofollow">http://social.msdn.microsoft.com/Forums/vstudio/en-US/985e039f-1610-4f62-9c3d-51ec7e1b1673/problem-with-maxreceivedmessagesize-webconfig-ignored</a>. Perhaps this has something to do with the new simplified binding methods used with .net 4.0 and later.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload