title: WCF: Protocol Exception - 400 Bad Request
body: <p>I'm developing a web site that can upload and download pictures. Download works fine, there aren't issue, but in the meanwhile the upload has a bad issue with pics bigger than 16 KB, telling me: "Protocol Exception: Error 400 Bad Request".</p>
  
  <p>That is telling me that I've to increase the size of MaxArrayLength in XmlDictionaryReaderQuotas, but I've already did that.</p>
  
  <p>I'll show you my webConfig:</p>
  
  <p>Client:</p>
  
  <pre><code>&lt;bindings&gt;
        &lt;basicHttpBinding&gt;
          &lt;binding name="BasicHttpBinding_IServiceImage" closeTimeout="00:01:00"
            openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00"
            allowCookies="false" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard"
            maxBufferSize="4194304" maxBufferPoolSize="4194304" maxReceivedMessageSize="4194304"
            messageEncoding="Text" textEncoding="utf-8" transferMode="Buffered"
            useDefaultWebProxy="true"&gt;
            &lt;readerQuotas maxDepth="4194304" maxStringContentLength="4194304" maxArrayLength="4194304"
              maxBytesPerRead="4194304" maxNameTableCharCount="4194304" /&gt;
            &lt;security mode="None"&gt;
              &lt;transport clientCredentialType="None" proxyCredentialType="None"
                realm="" /&gt;
              &lt;message clientCredentialType="UserName" algorithmSuite="Default" /&gt;
            &lt;/security&gt;
          &lt;/binding&gt;
        &lt;/basicHttpBinding&gt;
      &lt;/bindings&gt;
  </code></pre>
  
  <p>WCF:</p>
  
  <pre><code> &lt;bindings&gt;
        &lt;basicHttpBinding&gt;
          &lt;binding name="BasicHttpBinding_IServiceImage" closeTimeout="00:01:00"
          openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00"
          bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard"
          maxBufferPoolSize="4194304" maxReceivedMessageSize="4194304"
          messageEncoding="Text" textEncoding="utf-8" useDefaultWebProxy="true"
          allowCookies="false"&gt;
            &lt;readerQuotas maxDepth="4194304" maxStringContentLength="4194304" maxArrayLength="4194304"
            maxBytesPerRead="4194304" maxNameTableCharCount="4194304" /&gt;
            &lt;security mode="Message"&gt;
              &lt;transport clientCredentialType="None" proxyCredentialType="None" realm="" /&gt;
            &lt;/security&gt;
          &lt;/binding&gt;
        &lt;/basicHttpBinding&gt;
      &lt;/bindings&gt;
  </code></pre>
  
  <p>Any idea?</p>
  
  <p>Edit: I can upload file until they are tiny than 16KB, and I cannot found where I have to handle that value to increase.</p>
  
  <hr>
  
  <p>Sounds like for huge file, wcf has got some issue, so I have to change the "encodeMessage" to MTOM and move from BasicHttpBindings to wsHttpBindings.
  By the way that is not working yet, new issues appears on my code. Damn it.</p>
  
  <p>Client WebConfig:
      
        
      </p>
  
  <pre><code>&lt;bindings&gt;
  
    &lt;wsHttpBinding&gt;
      &lt;binding name="wsHttpBinding_IService1" closeTimeout="00:01:00"
        openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00"
        bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard"
        maxBufferPoolSize="4194304" maxReceivedMessageSize="4194304"
        messageEncoding="Mtom" textEncoding="utf-8" useDefaultWebProxy="true"
        allowCookies="false"&gt;
        &lt;readerQuotas maxDepth="4194304" maxStringContentLength="4194304"
          maxArrayLength="4194304" maxBytesPerRead="4194304" maxNameTableCharCount="4194304" /&gt;
        &lt;security mode="None"&gt;
          &lt;transport clientCredentialType="None" proxyCredentialType="None"
            realm="" /&gt;
          &lt;message clientCredentialType="UserName" algorithmSuite="Default" /&gt;
        &lt;/security&gt;
      &lt;/binding&gt;
    &lt;/wsHttpBinding&gt;
  &lt;/bindings&gt;
  </code></pre>
  
  <p>Service WebConfig:</p>
  
  <pre><code>&lt;bindings&gt;
    &lt;wsHttpBinding&gt;
      &lt;binding name="wsHttpBinding_IService1" closeTimeout="00:01:00"
        openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00"
        allowCookies="false" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard"
  
               maxBufferPoolSize="4194304" maxReceivedMessageSize="4194304"
        messageEncoding="Mtom" textEncoding="utf-8" useDefaultWebProxy="true"&gt;
        &lt;!--messageEncoding="Text" textEncoding="utf-8" maxBufferSize="4194304" transferMode="Buffered" --&gt;
        &lt;readerQuotas maxDepth="4194304" maxStringContentLength="4194304"
          maxArrayLength="4194304" maxBytesPerRead="4194304" maxNameTableCharCount="4194304" /&gt;
        &lt;security mode="None"&gt;
          &lt;transport clientCredentialType="None" proxyCredentialType="None"
            realm="" /&gt;
          &lt;message clientCredentialType="UserName" algorithmSuite="Default" /&gt;
        &lt;/security&gt;
      &lt;/binding&gt;
    &lt;/wsHttpBinding&gt;
  &lt;/bindings&gt;
  
  
  &lt;services&gt;
    &lt;service  name="WcfService.FileService" &gt;
      &lt;endpoint address="" binding="wsHttpBinding" contract="WcfService.IService1" /&gt;
    &lt;/service&gt;
  &lt;/services&gt;
  </code></pre>