title: WCF - Using ServiceRoutes instead of svc files -- My app states I need AspNetCompatability only when I first attempt to connect?
body: <pre><code>public class Global : HttpApplication
  {
      protected void Application_Start(object sender, EventArgs e)
      {
          RegisterRoutes(RouteTable.Routes);
      }
  
      private static void RegisterRoutes(ICollection&lt;RouteBase&gt; routes)
      {
          routes.Add(new ServiceRoute("Calculator", new WebServiceHostFactory(), typeof(CalculatorService)));
      }
  }
  
  &lt;system.serviceModel&gt;
    &lt;serviceHostingEnvironment multipleSiteBindingsEnabled="true" aspNetCompatibilityEnabled="true"&gt;
      &lt;serviceActivations&gt;
        &lt;add factory="System.ServiceModel.Activation.ServiceHostFactory"
             relativeAddress="Calculator.svc"
             service="MyServer.CalculatorService"/&gt;
      &lt;/serviceActivations&gt;
    &lt;/serviceHostingEnvironment&gt;
  &lt;/system.serviceModel&gt;
  </code></pre>
  
  <p>When I do this and go to <a href="http://localhost/MyApp/Calculator.svc" rel="nofollow">http://localhost/MyApp/Calculator.svc</a> I get an error saying I need AspNetCompatability. So I added <code>[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]</code> and it works, the only thing is I'm worried that I will want my service to use alternative means of transport (not just http) if I want to get into using alternative non-http bindings.</p>
  
  <p>The strange thing is that if I don't set the attribute to Allowed or Required then when I rebuild my page I get that error. After I get that error I hit refresh and everything is fine. And it isn't just if I query the svc through a web browser, but if I have an app it crashes the first time it connects (if the server was restarted) and afterwards it works. What gives?</p>