title: WCF REST 4.0 PUT/POST/DELETE not working (400 Bad Request)
body: <p>I have been working on setting up a WCF REST service in .NET 4.0. I have GET requests working, but any request that involves POSTing data to the server fails with a <code>HTTP 400 Bad Request</code>.</p>
  
  <p>This is my simple service:</p>
  
  <pre><code>[ServiceContract]
  [AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
  [ServiceBehavior(InstanceContextMode = InstanceContextMode.PerCall)]
  public class Service1
  {
      [WebGet(UriTemplate = "")]
      public string HelloWorld()
      {
          return "hello world";
      }
  
      [WebInvoke(UriTemplate = "", Method = "POST")]
      public string HelloWorldPost(string name)
      {
          return "hello " + name;
      }
  }
  </code></pre>
  
  <p>My 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.webServer&gt;
      &lt;modules runAllManagedModulesForAllRequests="true"&gt;
        &lt;add name="UrlRoutingModule" type="System.Web.Routing.UrlRoutingModule, System.Web, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" /&gt;
      &lt;/modules&gt;
    &lt;/system.webServer&gt;
  
    &lt;system.serviceModel&gt;
      &lt;serviceHostingEnvironment aspNetCompatibilityEnabled="true"/&gt;
      &lt;protocolMapping&gt;
        &lt;add scheme="http" binding="webHttpBinding" /&gt;      
      &lt;/protocolMapping&gt;
      &lt;standardEndpoints&gt;
        &lt;webHttpEndpoint&gt;
          &lt;!-- 
              Configure the WCF REST service base address via the global.asax.cs file and the default endpoint 
              via the attributes on the &lt;standardEndpoint&gt; element below
          --&gt;
          &lt;standardEndpoint name="" helpEnabled="true" automaticFormatSelectionEnabled="true"/&gt;
        &lt;/webHttpEndpoint&gt;
      &lt;/standardEndpoints&gt;
    &lt;/system.serviceModel&gt;
  
  &lt;/configuration&gt;
  </code></pre>
  
  <p>And my global.asax:</p>
  
  <pre><code>public class Global : HttpApplication
  {
      void Application_Start(object sender, EventArgs e)
      {
          RegisterRoutes();
      }
  
      private void RegisterRoutes()
      {
          RouteTable.Routes.Add(new ServiceRoute("Service1", new WebServiceHostFactory(), typeof(Service1)));
      }
  }
  </code></pre>
  
  <p>Basically, everything is default from the template, but I've just simplified the <code>Service1</code>. I have tried both running it through the debugger and passing a request through Fiddler and running it in IIS and doing the same, as well as using a simple console application to fake the POST but I always get the <code>400 Bad Request</code> error and I have no idea why. I've looked all over the internet and can't figure anything out.</p>
  
  <p>I've tried both of the following request examples (neither work):</p>
  
  <p>XML:</p>
  
  <pre><code>&lt;string xmlns="http://schemas.microsoft.com/2003/10/Serialization/"&gt;String content&lt;/string&gt;
  </code></pre>
  
  <p>JSON:</p>
  
  <pre><code>"String content"
  </code></pre>