title: 400.0 Bad Request on REST API on Azure Web Site
body: <p>I have migrated a REST service to an Azure web site, but it keeps coming back with a <code>400.0 Bad Request</code> error (error code zero).</p>
  
  <p>The service works locally, and works perfectly when running in a Web Role.  After moving into a Web Site, it started coming back with the 400.0 error.</p>
  
  <p>My web.config:</p>
  
  <pre><code>&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;standardEndpoints&gt;
          &lt;webHttpEndpoint&gt;
              &lt;standardEndpoint name="" helpEnabled="true" automaticFormatSelectionEnabled="false" /&gt;
          &lt;/webHttpEndpoint&gt;
      &lt;/standardEndpoints&gt;
  &lt;/system.serviceModel&gt;
  </code></pre>
  
  <p>I already have ASP.NET compatibility set in my class:</p>
  
  <pre><code>[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Required)]
  [ServiceBehavior(InstanceContextMode = InstanceContextMode.PerSession, ConcurrencyMode = ConcurrencyMode.Multiple)]
  public class BookingService { ... }
  </code></pre>
  
  <p>and the proper routing defined in Global.asax.cs:</p>
  
  <pre><code>private void Application_Start (object sender, EventArgs e) {
      RouteTable.Routes.Add(new ServiceRoute("booking/service", new WebServiceHostFactory(), typeof(BookingService)));
  }
  </code></pre>
  
  <p>Now when I try to access the REST API locally, it works fine:</p>
  
  <pre><code>http://localhost/booking/service/help
  </code></pre>
  
  <p>However, after uploading the web service into an Azure Web Site and doing:</p>
  
  <pre><code>http://xxx.azurewebsites.net/booking/service/help
  </code></pre>
  
  <p>it came back with a 400.0 Bad Request.  Detailed error logs show:</p>
  
  <pre><code>Request: ManagedPipelineHandler
  Notification: ExecuteRequestHandler
  Handler:  System.ServiceModel.Activation.AspNetRouteServiceHttpHandler
  Error code: 0x00000000
  </code></pre>
  
  <p>I am at a total lost.  Googling the web didn't yield anything helpful.  I tried putting the following into web.config:</p>
  
  <pre><code>&lt;handlers&gt;
      &lt;add name="UrlRoutingHandler" preCondition="integratedMode" verb="*" path="UrlRouting.axd" type="Foo.RoutingHandler" /&gt;
  &lt;/handlers&gt;
  </code></pre>
  
  <p>and defining a handler by extending <code>UrlRoutingHandler</code> and defining <code>VerifyAndProcessRequest</code> but it still doesn't work.</p>