title: WCF Service Error : Exception Details: System.Net.WebException: The remote server returned an error: (400) Bad Request
body: <p>I created a web service to upload files over http but on my first try, it is failing.</p>
  
  <p>My web service is running on my local computer's IIS 7, under ASP.NET 4 Integrated App Pool. Here this is my web service's web.config;</p>
  
  <pre><code>&lt;?xml version="1.0"?&gt;
  &lt;configuration&gt;
  
    &lt;system.web&gt;
      &lt;compilation debug="true" targetFramework="4.0" /&gt;
    &lt;/system.web&gt;
  
    &lt;system.serviceModel&gt;
  
      &lt;behaviors&gt;
  
        &lt;serviceBehaviors&gt;
  
          &lt;behavior&gt;
            &lt;!-- To avoid disclosing metadata information, set the value below to false and remove the metadata endpoint above before deployment --&gt;
            &lt;serviceMetadata httpGetEnabled="true"/&gt;
            &lt;!-- To receive exception details in faults for debugging purposes, set the value below to true.  Set to false before deployment to avoid disclosing exception information --&gt;
            &lt;serviceDebug includeExceptionDetailInFaults="false"/&gt;
          &lt;/behavior&gt;
  
          &lt;behavior name="TransferServiceBehavior"&gt;
            &lt;dataContractSerializer maxItemsInObjectGraph="2147483647" /&gt;
            &lt;serviceThrottling maxConcurrentCalls="500"
                               maxConcurrentSessions="500" maxConcurrentInstances="500" /&gt;  
          &lt;/behavior&gt;
  
        &lt;/serviceBehaviors&gt;
  
      &lt;/behaviors&gt;
  
      &lt;bindings&gt;
        &lt;basicHttpBinding&gt;
          &lt;binding name="TransferService" maxReceivedMessageSize="2147483647"
                   maxBufferSize="2147483647" transferMode="Streamed"&gt;
            &lt;readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647" 
                          maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" /&gt;
            &lt;security mode="None"&gt;
              &lt;transport clientCredentialType="None" /&gt;
            &lt;/security&gt;
          &lt;/binding&gt;
        &lt;/basicHttpBinding&gt;
      &lt;/bindings&gt;
  
      &lt;services&gt;
  
        &lt;service behaviorConfiguration="TransferServiceBehavior" name="TransferService"&gt;
          &lt;endpoint address="" binding="basicHttpBinding" bindingConfiguration="TransferService"
                  contract ="ITransferService"&gt;
          &lt;/endpoint&gt;
        &lt;/service&gt;
  
      &lt;/services&gt;
  
      &lt;serviceHostingEnvironment multipleSiteBindingsEnabled="true" aspNetCompatibilityEnabled="true" /&gt;
  
    &lt;/system.serviceModel&gt;
  
   &lt;system.webServer&gt;
      &lt;modules runAllManagedModulesForAllRequests="true"/&gt;
    &lt;/system.webServer&gt;
  
    &lt;system.web&gt;
      &lt;!--&lt;httpRuntime maxRequestLength="2097151" /&gt;--&gt;
      &lt;httpRuntime maxRequestLength="2097151" 
                   useFullyQualifiedRedirectUrl="true" executionTimeout="14400"   /&gt;
    &lt;/system.web&gt;
  
  &lt;/configuration&gt;
  </code></pre>
  
  <p>This is the web.config file of the client;</p>
  
  <pre><code>&lt;configuration&gt;
      &lt;system.web&gt;
          &lt;compilation debug="true" targetFramework="4.0" /&gt;
          &lt;httpRuntime maxRequestLength="2097150" /&gt;
      &lt;/system.web&gt;
  
      &lt;system.serviceModel&gt;
  
          &lt;bindings&gt;
              &lt;basicHttpBinding&gt;
                &lt;binding name="BasicHttpBinding_ITransferService" closeTimeout="04:01:00"
                    openTimeout="04:01:00" receiveTimeout="04:10:00" sendTimeout="04:01:00"
                    allowCookies="false" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard"
                    maxBufferSize="2147483647" maxBufferPoolSize="2147483647" maxReceivedMessageSize="2147483647"
                    messageEncoding="Text" textEncoding="utf-8" transferMode="Streamed"
                    useDefaultWebProxy="true"&gt;
                  &lt;readerQuotas maxDepth="128" maxStringContentLength="2147483647" maxArrayLength="2147483647"
                      maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" /&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;
  
          &lt;client&gt;
              &lt;endpoint address="http://localhost:81/TransferService.svc" binding="basicHttpBinding"
                  bindingConfiguration="BasicHttpBinding_ITransferService" contract="TransferService.ITransferService"
                  name="BasicHttpBinding_ITransferService" /&gt;
          &lt;/client&gt;
  
      &lt;/system.serviceModel&gt;
  &lt;/configuration&gt;
  </code></pre>
  
  <p>Here is the error I receive;</p>
  
  <blockquote>
    <p>The remote server returned an error: (400) Bad Request.</p>
    
    <p>Description: An unhandled exception occurred during the execution of
    the current web request. Please review the stack trace for more
    information about the error and where it originated in the code. </p>
    
    <p>Exception Details: System.Net.WebException: The remote server returned
    an error: (400) Bad Request.</p>
    
    <p>Source Error: </p>
    
    <p>Line 120:<br>
    [System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Advanced)]
    Line 121:<br>
    FileUploadWcfServiceClient.TransferService.UploadFileResponse
    FileUploadWcfServiceClient.TransferService.ITransferService.UploadFile(FileUploadWcfServiceClient.TransferService.RemoteFileInfo
    request) { Line 122:            return
    base.Channel.UploadFile(request); Line 123:        } Line 124:        </p>
    
    <p>Source File:
    C:\Apps\FileUploadWcfService\FileUploadWcfServiceClient\Service
    References\TransferService\Reference.cs    Line: 122 </p>
    
    <p>Stack Trace: </p>
    
    <p>[WebException: The remote server returned an error: (400) Bad
    Request.]    System.Net.HttpWebRequest.GetResponse() +6111059<br>
    System.ServiceModel.Channels.HttpChannelRequest.WaitForReply(TimeSpan
    timeout) +48</p>
    
    <p>[ProtocolException: The remote server returned an unexpected response:
    (400) Bad Request.]<br>
    System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage
    reqMsg, IMessage retMsg) +9456095<br>
    System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData&amp;
    msgData, Int32 type) +345<br>
    FileUploadWcfServiceClient.TransferService.ITransferService.UploadFile(RemoteFileInfo
    request) +0<br>
    FileUploadWcfServiceClient.TransferService.TransferServiceClient.FileUploadWcfServiceClient.TransferService.ITransferService.UploadFile(RemoteFileInfo
    request) in
    C:\Apps\FileUploadWcfService\FileUploadWcfServiceClient\Service
    References\TransferService\Reference.cs:122<br>
    FileUploadWcfServiceClient.Default.Button1_Click(Object sender,
    EventArgs e) in
    C:\Apps\FileUploadWcfService\FileUploadWcfServiceClient\Default.aspx.cs:85
    System.Web.UI.WebControls.Button.OnClick(EventArgs e) +118<br>
    System.Web.UI.WebControls.Button.RaisePostBackEvent(String
    eventArgument) +112<br>
    System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String
    eventArgument) +10<br>
    System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler
    sourceControl, String eventArgument) +13<br>
    System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData)
    +36    System.Web.UI.Page.ProcessRequestMain(Boolean
    includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
    +5563</p>
    
    <p>Version Information: Microsoft .NET Framework Version:4.0.30319;
    ASP.NET Version:4.0.30319.225</p>
  </blockquote>
  
  <p>The file that I am trying to upload is 217 KB so I am guessing the file size is not the problem here.</p>
  
  <p>What do you think causing the error?</p>