title: WCF catching maxReceivedMessageSize error
body: <p>When trying to send a large file to my WCF service, I'm getting this error:</p>
  
  <pre><code>400 - http://myservice/newfilebiggie
  Date: Thu, 25 Feb 2016 09:51:42 GMT
  Execution Time (ms): 21477.116
  Content-Type: text/html
  Content-Length: -1
  
  Body:
  &lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt;
  &lt;html xmlns="http://www.w3.org/1999/xhtml"&gt;
    &lt;head&gt;
      &lt;title&gt;Request Error&lt;/title&gt;
      &lt;style&gt;BODY
  {
       color: #000000; background-color: white; font-family: Verdana; margin-left: 0px; margin-top: 0px;
  } #content
  {
       margin-left: 30px; font-size: .70em; padding-bottom: 2em;
  } A:link
  {
       color: #336699; font-weight: bold; text-decoration: underline;
  } A:visited
  {
       color: #6699cc; font-weight: bold; text-decoration: underline;
  } A:active
  {
       color: #336699; font-weight: bold; text-decoration: underline;
  } .heading1
  {
       background-color: #003366; border-bottom: #336699 6px solid; color: #ffffff; font-family: Tahoma; font-size: 26px; font-weight: normal;margin: 0em 0em 10px -20px; padding-bottom: 8px; padding-left: 30px;padding-top: 16px;
  } pre
  {
       font-size:small; background-color: #e5e5cc; padding: 5px; font-family: Courier New; margin-top: 0px; border: 1px #f0f0e0 solid; white-space: pre-wrap; white-space: -pre-wrap; word-wrap: break-word;
  } table
  {
       border-collapse: collapse; border-spacing: 0px; font-family: Verdana;
  } table th
  {
       border-right: 2px white solid; border-bottom: 2px white solid; font-weight: bold; background-color: #cecf9c;
  } table td
  {
       border-right: 2px white solid; border-bottom: 2px white solid; background-color: #e5e5cc;
  }&lt;/style&gt;
    &lt;/head&gt;
    &lt;body&gt;
      &lt;div id="content"&gt;
        &lt;p class="heading1"&gt;Request Error&lt;/p&gt;
        &lt;p&gt;The server encountered an error processing the request. The exception message is 'The maximum message size quota for incoming messages (10485760) has been exceeded. To increase the quota,
  use the MaxReceivedMessageSize property on the appropriate binding element.'. See server logs for more details. The exception stack trace is: &lt;/p&gt;
        &lt;p&gt;   at System.ServiceModel.Channels.MaxMessageSizeStream.PrepareRead(Int32 bytesToRead)
     at System.ServiceModel.Channels.MaxMessageSizeStream.Read(Byte
  [
  ] buffer,
  Int32 offset,
  Int32 count)
     at System.IO.BufferedStream.Read(Byte
  [
  ] array,
  Int32 offset,
  Int32 count)
     at System.Runtime.Serialization.Json.JsonEncodingStreamWrapper.Read(Byte
  [
  ] buffer,
  Int32 offset,
  Int32 count)
     at System.Xml.XmlBufferReader.TryEnsureBytes(Int32 count)
     at System.Runtime.Serialization.Json.XmlJsonReader.ReadNumericalText()
     at System.Runtime.Serialization.Json.XmlJsonReader.Read()
     at System.Xml.XmlBaseReader.ReadStartElement()
     at System.Xml.XmlDictionaryReader.ReadElementContentAsInt()
     at System.Runtime.Serialization.Json.ByteArrayHelperWithString.ReadArray(XmlDictionaryReader reader,
  String localName,
  String namespaceUri,
  Byte
  [
  ] array,
  Int32 offset,
  Int32 count)
     at System.Xml.ArrayHelper`2.ReadArray(XmlDictionaryReader reader,
  TArgument localName,
  TArgument namespaceUri,
  Int32 maxArrayLength)
     at System.Runtime.Serialization.Json.JsonReaderDelegator.ReadContentAsBase64()
     at System.Runtime.Serialization.Json.JsonReaderDelegator.ReadElementContentAsBase64()
     at ReadResumeUploadDTOFromJson(XmlReaderDelegator ,
  XmlObjectSerializerReadContextComplexJson ,
  XmlDictionaryString ,
  XmlDictionaryString
  [
  ] )
     at System.Runtime.Serialization.Json.JsonClassDataContract.ReadJsonValueCore(XmlReaderDelegator jsonReader,
  XmlObjectSerializerReadContextComplexJson context)
     at System.Runtime.Serialization.Json.XmlObjectSerializerReadContextComplexJson.ReadDataContractValue(DataContract dataContract,
  XmlReaderDelegator reader)
     at System.Runtime.Serialization.XmlObjectSerializerReadContext.InternalDeserialize(XmlReaderDelegator reader,
  String name,
  String ns,
  Type declaredType,
  DataContract&amp;amp; dataContract)
     at System.Runtime.Serialization.XmlObjectSerializerReadContextComplex.InternalDeserialize(XmlReaderDelegator xmlReader,
  Type declaredType,
  DataContract dataContract,
  String name,
  String ns)
     at System.Runtime.Serialization.Json.DataContractJsonSerializer.InternalReadObject(XmlReaderDelegator xmlReader,
  Boolean verifyObjectName)
     at System.Runtime.Serialization.XmlObjectSerializer.InternalReadObject(XmlReaderDelegator reader,
  Boolean verifyObjectName,
  DataContractResolver dataContractResolver)
     at System.Runtime.Serialization.XmlObjectSerializer.ReadObjectHandleExceptions(XmlReaderDelegator reader,
  Boolean verifyObjectName,
  DataContractResolver dataContractResolver)
     at System.Runtime.Serialization.Json.DataContractJsonSerializer.ReadObject(XmlDictionaryReader reader,
  Boolean verifyObjectName)
     at System.ServiceModel.Dispatcher.SingleBodyParameterMessageFormatter.ReadObject(Message message)
     at System.ServiceModel.Dispatcher.SingleBodyParameterDataContractMessageFormatter.ReadObject(Message message)
     at System.ServiceModel.Dispatcher.SingleBodyParameterMessageFormatter.DeserializeRequest(Message message,
  Object
  [
  ] parameters)
     at System.ServiceModel.Dispatcher.DemultiplexingDispatchMessageFormatter.DeserializeRequest(Message message,
  Object
  [
  ] parameters)
     at System.ServiceModel.Dispatcher.UriTemplateDispatchFormatter.DeserializeRequest(Message message,
  Object
  [
  ] parameters)
     at System.ServiceModel.Dispatcher.CompositeDispatchFormatter.DeserializeRequest(Message message,
  Object
  [
  ] parameters)
     at System.ServiceModel.Dispatcher.DispatchOperationRuntime.DeserializeInputs(MessageRpc&amp;amp; rpc)
     at System.ServiceModel.Dispatcher.DispatchOperationRuntime.InvokeBegin(MessageRpc&amp;amp; rpc)
     at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage5(MessageRpc&amp;amp; rpc)
     at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage41(MessageRpc&amp;amp; rpc)
     at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage4(MessageRpc&amp;amp; rpc)
     at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage31(MessageRpc&amp;amp; rpc)
     at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage3(MessageRpc&amp;amp; rpc)
     at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage2(MessageRpc&amp;amp; rpc)
     at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage11(MessageRpc&amp;amp; rpc)
     at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage1(MessageRpc&amp;amp; rpc)
     at System.ServiceModel.Dispatcher.MessageRpc.Process(Boolean isOperationContextSet)&lt;/p&gt;
      &lt;/div&gt;
    &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>Is there a way for me to catch this error without increasing my MaxReceivedMessageSize property in my config?</p>
  
  <p>If possible, I would like to return a 400 error without returning the whole html error.</p>