title: ServiceRoute does not work when routePrefix is a path
body: <p>When I try to access my WCF service at the following address it works fine: </p>
  
  <pre><code>http://localhost/webservices/main.svc
  </code></pre>
  
  <p>Great.  But I want to be able to call this service in following way:</p>
  
  <pre><code>http://localhost/api/main
  </code></pre>
  
  <p>So I am attempting to put in the proper ServiceRoute within the RouteConfig definitions in my MVC.  I am able to make the routing work when the routePrefix variable is singular.  But I cannot get it to work when routePrefix it is a path such as, as in my case, I want to map a route to ~/api/main.   </p>
  
  <p>I've scoured around The Google and this particular question is not common.   I am pretty much seeking to accomplish the similar to what is stated in the accepted answer of the following previously posted question on this topic:  </p>
  
  <p><a href="https://stackoverflow.com/questions/4047485/expose-wcf-services-that-belong-to-an-area-in-mvc-app-at-a-routed-path">Expose WCF services that belong to an Area in MVC app at a routed path</a></p>
  
  <p>I also attempted to implement a route constraint as suggested here:  <a href="http://geekswithblogs.net/michelotti/archive/2010/09/22/wcf-rest-services-inside-mvc-projects.aspx" rel="nofollow noreferrer">http://geekswithblogs.net/michelotti/archive/2010/09/22/wcf-rest-services-inside-mvc-projects.aspx</a></p>
  
  <p>But still get the following error:</p>
  
  <pre><code>No HTTP resource was found that matches the request URI 'http://localhost/api/main'.
  No type was found that matches the controller named 'main'.
  </code></pre>
  
  <p>Here is what I've attempted so far:</p>
  
  <pre><code>Imports System.Web.Mvc 
  Imports System.Web.Routing 
  Imports System.ServiceModel.Activation
  Imports MyServiceLibrary
  
  Public Class RouteConfig
      Public Shared Sub RegisterRoutes(ByVal routes As RouteCollection)
         [..other routing stuff...]
  
         routes.Add(New ServiceRoute("api/main", New ServiceHostFactory(), _
             GetType(MyServiceLibrary.main)))
  
         routes.MapRoute("Default", "{controller}/{action}/{id}", New With { _
              Key .controller = "Default1", _
              Key .action = "Index", _
              Key .id = UrlParameter.Optional}, _
              New With {Key .controller = "^(?!main).*"})
  
  
         [..other routing stuff...]
      End Sub
  End Class
  </code></pre>
  
  <p>Can't seem to figure out the fix on this.   </p>
  
  <p><b>EDIT 2:</b></p>
  
  <p>When I first posted this question I had a problem with what turned out to be malformed VB syntax.</p>
  
  <p>The original INCORRECT syntax:</p>
  
  <pre><code>routes.Add(new ServiceRoute("api/main", new ServiceHostFactory(), _
                typeof(MyServiceLibrary.main)))
  </code></pre>
  
  <p>The CORRECT vb syntax should be:</p>
  
  <pre><code>routes.Add(New ServiceRoute("api/main", New ServiceHostFactory(), _
             GetType(MyServiceLibrary.main)))
  </code></pre>
  
  <p>Notice that in VB you should use <b>GetType</b> instead of <b>typeof</b>.  Fixing this was a good step forward, but did not solve the underlying problem.  </p>
  
  <p><b>EDIT 3:</b></p>
  
  <p>Well, turns out if I modify the ServiceRoute as follows, then IT WORKS:</p>
  
  <pre><code>routes.Add(New ServiceRoute("main", New ServiceHostFactory(), _
             GetType(MyServiceLibrary.main)))
  </code></pre>
  
  <p>So, the question is how to create the route i desire "api/main"...</p>
  
  <p><b>EDIT 4:</b></p>
  
  <p>I thought I might have found the solution here:  <a href="https://stackoverflow.com/questions/3186858/can-a-wcf-serviceroute-route-prefix-contain-a-path-value">Can a WCF ServiceRoute Route Prefix contain a path value?</a></p>
  
  <p>The solution there notably implements WebServiceHostFactory instead of ServiceHostFactory.  I tried it, but it didn't work for me.  </p>