none
Error 400 on WCF maxStringContentLength RRS feed

  • Question

  • I have inherited a WCF web service which is running ASP.Net 2 on IIS 7.

    However, we have a problem when posting large amounts of data, it produces an error 400 Bad Request.

    I've added element, as a trace is producing the following error

    "There was an error deserializing the object of type CIX.API.Contracts.PostMessage. The maximum string content length quota (8192) has been exceeded while reading XML data. This quota may be increased by changing the MaxStringContentLength property on the XmlDictionaryReaderQuotas object used when creating the XML reader. Line 51, position 322."

    I've included the whole system.serviceModel below - can anyone spot anything that's amiss? I've been trying to fix this for some time, but I've been unable to and any help would be very much appreciated.

     
        

      <system.serviceModel>

        <extensions>
          <behaviorExtensions>
            <add name="restHttpBehavior" type="CIX.API.Behaviors.ErrorHandling.RestBehaviorExtension, CIX.API, Version=2.0.0.0, Culture=neutral, PublicKeyToken=null"/>
          </behaviorExtensions>
          <bindingElementExtensions>
            <add name="secureCIXChannel" type="CIX.API.Channels.SecureCIX.SecureCIXBindingExtension, CIX.API"/>
            <add name="hlRestChannel" type="CIX.API.Channels.HLRest.HLBindingExtension, CIX.API"/>
          </bindingElementExtensions>
        </extensions>
    <bindings>
          <customBinding>
            <binding name="CIXBinding" maxReceivedMessageSize="2147483647" maxBufferSize="2147483647">
              <secureCIXChannel/>
         <webMessageEncoding>
       <readerQuotas maxStringContentLength="2147483647" />
         </webMessageEncoding>
              <httpTransport manualAddressing="true"/>
            </binding> 
          </customBinding>
    <basicHttpBinding>
            <binding name="defaultBinding">
              <readerQuotas maxStringContentLength="2147483647" />
            </binding>
          </basicHttpBinding>
        </bindings>
        <services>
          <service behaviorConfiguration="CIX.API.ServiceBehavior" name="CIX.API.CIX">
            <endpoint contract="CIX.API.ICIX" address="" binding="customBinding" bindingConfiguration="CIXBinding" behaviorConfiguration="CIX.API.CIXBehavior"/>
          </service>
        </services>    
        <behaviors>
          <endpointBehaviors>
            <behavior name="CIX.API.CIXBehavior">
              <dataContractSerializer maxItemsInObjectGraph="200000"/>
              <restHttpBehavior/>
            </behavior>
          </endpointBehaviors>
          <serviceBehaviors>
            <behavior name="CIX.API.ServiceBehavior">
              <serviceMetadata httpGetEnabled="true"/>
              <serviceDebug includeExceptionDetailInFaults="true"/>
            </behavior>
            <behavior name="CIX.Web.CIXBehavior">
              <serviceMetadata httpGetEnabled="true"/>
              <serviceDebug includeExceptionDetailInFaults="true"/>
            </behavior>
          </serviceBehaviors>
        </behaviors>
      </system.serviceModel>

    Thanks,

    Friday, June 5, 2015 9:44 AM

All replies

  • If you are sending the data to the client and sending it back to the service, then both config file settings for maxStringContentLength must be set.  
    Friday, June 5, 2015 1:21 PM
  • If you want to override the default binding settings for any service  no matter how many you have defined in the service side config file,  then you must use a custom binding and point each service binding to its custom binding.

    I can say that tne below is not going to work and it's not being overriden.

    <basicHttpBinding>
            <binding name="defaultBinding">
              <readerQuotas maxStringContentLength="2147483647" />
            </binding>
      </basicHttpBinding>

    Friday, June 5, 2015 7:38 PM
  • Well, all I can tell you is that your usage of Custom bindings is not overriding default settings, and you need to rethink it.
    Saturday, June 6, 2015 6:04 PM
  • "There was an error deserializing the object of type CIX.API.Contracts.PostMessage. The maximum string content length quota (8192) has been exceeded while reading XML data. This quota may be increased by changing the MaxStringContentLength property on  the XmlDictionaryReaderQuotas object used when creating the XML reader. Line 51, position 322."

    hi lesliecostar,
      As per this case, refer the following details :

    1.MaxReceivedMessageSize>> This property is used to limit the overall message size which includes the message content and header information.

    2.MaxStringContentLength>> This is used by the XmlReader to deserialize the message content

    3.when using the basicHttp binding, the default TransferMode is set to buffered. When this is the case, both MaxBufferSize and MaxReceivedMessageSize should be the same.

    4.A message can be sent to the Web Service that does not exceed the message size setting, but it may be bigger than the message content setting. When this is the case, the server returns a deserialization error which is created by the XmlReader because the max content length of the XML has been exceeded. So to address the 400 bad request errors.

    <customBinding>
     <binding name="CIXBinding" maxReceivedMessageSize="2147483647" maxBufferSize="2147483647">
     <secureCIXChannel/>
     <webMessageEncoding>
      <readerQuotas maxStringContentLength="2000000000" />
     </webMessageEncoding>
     <httpTransport manualAddressing="true"/>
    </binding> 
    </customBinding>
    Tuesday, June 30, 2015 6:24 AM