Protocol Exception in MVC: The remote server returned an unexpected response: (400) Bad Request. RRS feed

  • Question

  • Getting this exception while sending JSON data from controller to WCF in MVC :

    When I'm adding 7 rows in my grid, the data is getting added successfully, but when I'm trying to add 8 rows, that time it is throwing below exception.

     The remote server returned an unexpected response: (400) Bad Request.

    I've set the max integer value for maxReceivedMessageSize. The client web.config looks like:

    <binding name="WSHttpBinding_MyService" closeTimeout="00:01:00"
              openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00"
              bypassProxyOnLocal="false" maxBufferPoolSize="2147483647" maxReceivedMessageSize="2147483647"
              useDefaultWebProxy="true" allowCookies="false">
              <security mode="TransportWithMessageCredential">
                <transport clientCredentialType="None" realm="" />
                <message clientCredentialType="UserName" />

    In service web.config:

            <binding name="MyWSHttpBinding" closeTimeout="00:01:00" transactionFlow="true"  >
              <readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647" maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" />
              <security mode="TransportWithMessageCredential">
                <message clientCredentialType="UserName"/>



    <service name="Test.Sec.Tss.Services.MyService" behaviorConfiguration="ServiceBehavior">
            <endpoint address="secure" binding="wsHttpBinding"  contract="Test.Sec.Tss.Services.IMyService" behaviorConfiguration="ServiceSoapBehavior" bindingConfiguration="MyWSHttpBinding"></endpoint>


    Traffic observed in Fiddler:

    Bytes Sent:      5,503          (headers:1,354; body:4,149)  Bytes Received:  394            (headers:297; body:97)

    Thanks in advance and any help will be much appreciated.



    Tuesday, May 7, 2013 5:07 AM


  • Hi,

    You need to make sure that the request length ASP.NET allows is also set in addition to WCF's various settings. For ASP.NET the setting you're looking for is maxRequestLength on the httpRuntime element. The default for this setting is only 4MB, so that would explain why you run into an issue.

    That would look a little something like this for a 512MB maxLength:

        <httpRuntime maxRequestLength="524288" />

        <!-- rest of your config here -->

    If this still can not solve your problem, Please try to review the Windows Event Log and see if you can find relevant information about your service. and set includeExceptionDetailInFaults to true in your configure file to get more about the error too. Using the wcf trace is also a good way.

    Best Regards.

    Amy Peng
    MSDN Community Support | Feedback to us
    Develop and promote your apps in Windows Store
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Thursday, May 9, 2013 1:51 AM