title: uploading large xml to WCF REST service -> 400 Bad request
body: <p>I have been trying to search for this error but no luck so far.</p>
  
  <p>So I have a service on my client with this web.config</p>
  
  <pre><code>  &lt;system.serviceModel&gt;
  &lt;serviceHostingEnvironment&gt;
    &lt;baseAddressPrefixFilters&gt;
      &lt;add prefix="http://www.mywebsite.com/"/&gt;
    &lt;/baseAddressPrefixFilters&gt;
  &lt;/serviceHostingEnvironment&gt;
  &lt;services&gt;
    &lt;service behaviorConfiguration="ServiceBehavior" name="UploadService"&gt;
      &lt;endpoint address="" binding="basicHttpBinding" bindingConfiguration=""
        contract="IUploadService"&gt;
        &lt;identity&gt;
          &lt;dns value="http://www.mywebsites.com/" /&gt;
        &lt;/identity&gt;
      &lt;/endpoint&gt;
      &lt;endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" /&gt;
    &lt;/service&gt;
  &lt;/services&gt;
  &lt;behaviors&gt;
    &lt;serviceBehaviors&gt;
      &lt;behavior name="ServiceBehavior" maxReceivedMessageSize="4194304"&gt;
        &lt;serviceMetadata httpGetEnabled="true" /&gt;
        &lt;serviceDebug includeExceptionDetailInFaults="true" /&gt;
      &lt;/behavior&gt;
    &lt;/serviceBehaviors&gt;
  &lt;/behaviors&gt;
  </code></pre>
  
  <p></p>
  
  <p>and on the client I have this configuration</p>
  
  <pre><code>  &lt;system.serviceModel&gt;
  &lt;bindings&gt;
    &lt;wsHttpBinding&gt;
      &lt;binding name="WSHttpBinding_IUploadService" closeTimeout="00:01:00"
        openTimeout="00:01:00" receiveTimeout="00:30:00" sendTimeout="00:30:00"
        bypassProxyOnLocal="false" transactionFlow="false" hostNameComparisonMode="StrongWildcard"
        maxBufferPoolSize="524288" maxReceivedMessageSize="4194304"
        messageEncoding="Text" textEncoding="utf-8" useDefaultWebProxy="true"
        allowCookies="false"&gt;
        &lt;readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647"
          maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" /&gt;
        &lt;reliableSession ordered="true" inactivityTimeout="00:30:00"
          enabled="false" /&gt;
        &lt;security mode="Message"&gt;
          &lt;transport clientCredentialType="Windows" proxyCredentialType="None"
            realm=""&gt;
            &lt;extendedProtectionPolicy policyEnforcement="Never" /&gt;
          &lt;/transport&gt;
          &lt;message clientCredentialType="Windows" negotiateServiceCredential="true"
            algorithmSuite="Default" establishSecurityContext="true" /&gt;
        &lt;/security&gt;
      &lt;/binding&gt;
    &lt;/wsHttpBinding&gt;
  &lt;/bindings&gt;
  &lt;client&gt;
    &lt;endpoint address="http://www.mywebsite.com/UploadService.svc"
      binding="basicHttpBinding" bindingConfiguration="" contract="IUploadService"
      name="WSHttpBinding_IUploadService"&gt;
      &lt;identity&gt;
        &lt;dns value="http://www.mywebsite.com/" /&gt;
      &lt;/identity&gt;
    &lt;/endpoint&gt;
  &lt;/client&gt;
  </code></pre>
  
  <p></p>
  
  <p>and I am uploading the files like this :-</p>
  
  <pre><code>        using (Stream stream = new FileStream(strFilePath, FileMode.Open, FileAccess.Read))
          {
              try
              {
                  using (UploadServiceClient upc = new UploadServiceClient())
                  {
                      upc.UploadFile(stream);
                  }
  
              }
              catch (Exception exc)
              {
  
              }
          }
  </code></pre>
  
  <p>for small files it works fine, but for large XML files, this failes with 400 Bad Request.  What I can do to change these settings to get large XML file to transfer?</p>
  
  <p>Thanks for your help and time</p>
  
  <p>UPDATED Client app.config</p>
  
  <pre><code>  &lt;system.serviceModel&gt;
  &lt;bindings&gt;
    &lt;basicHttpBinding&gt;
      &lt;binding name="basicHttpBinding_IUploadService" receiveTimeout="00:20:00"
        bypassProxyOnLocal="true" maxBufferSize="4194304" maxReceivedMessageSize="4194304"
        messageEncoding="Mtom" transferMode="Streamed"&gt;
        &lt;readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647"
          maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" /&gt;
        &lt;security&gt;
          &lt;transport&gt;
            &lt;extendedProtectionPolicy policyEnforcement="Never" /&gt;
          &lt;/transport&gt;
        &lt;/security&gt;
      &lt;/binding&gt;
    &lt;/basicHttpBinding&gt;
  &lt;/bindings&gt;
  &lt;client&gt;
    &lt;endpoint address="http://www.mywebsite.com/UploadService.svc"
      binding="basicHttpBinding" bindingConfiguration="" contract="IUploadService"
      name="basicHttpBinding_IUploadService"&gt;
      &lt;identity&gt;
        &lt;dns value="http://www.mywebsite.com/" /&gt;
      &lt;/identity&gt;
    &lt;/endpoint&gt;
  &lt;/client&gt;
  </code></pre>
  
  <p></p>