Thanks to Ladislav’s proposal to use ServiceRoute, I developed how to do it, but I'm not sure that it is perfect, here’s what I did (in case the search engines find it and can improve it, etc.):
Created an extension method for ComponentRegistration as follows:
public static ComponentRegistration<T> AddServiceRoute<T>( this ComponentRegistration<T> registration, string routePrefix, ServiceHostFactoryBase serviceHostFactory, string routeName) where T : class { var route = new ServiceRoute("Services/" + routePrefix + ".svc", serviceHostFactory, registration .Implementation .GetInterfaces() .Single()); RouteTable.Routes.Add(routeName, route); return registration; }
What this means is that it adds a service route, which places the service in the Services folder and overlayes the .svc extension (I will probably delete this). Notice, I assume that the service implements only one interface, but in my case this is normal, and I think this is good practice.
I'm not sure if this is the best place to use this extension method, or even if the extension method is really necessary at all - maybe I should do it with the help of the service host creator or something else, I don’t know
Then, in MapRoute calls, I definitely added this to the restriction parameter in accordance with the question Routing MVC2 with WCF ServiceRoute: Html.ActionLink displaying invalid links!
new { controller = @"^(?!Services).*" }
It just does everything that starts Services that cannot be negotiated as a controller. I don’t really like it, because I have to add it to all my routes - I would prefer to globally make the Services folder into the service converter or something (I don’t know enough about MVC!).
Finally, in my windsor installer, I will register the service as follows:
container.AddFacility<WcfFacility>( f => { f.Services.AspNetCompatibility = AspNetCompatibilityRequirementsMode.Allowed; f.CloseTimeout = TimeSpan.Zero; }); container.Register( Component .For<IMyService>() .ImplementedBy<MyService>() .AsWcfService(new DefaultServiceModel() .AddEndpoints(WcfEndpoint.BoundTo(new WebHttpBinding())) .Hosted() .PublishMetadata()) .AddServiceRoute("MyService", new DefaultServiceHostFactory(), null));
After that, I can go to the service and pick it up and build it perfectly!
As I said, this may not be the best way to do this, but it works.