Can a WCF ServiceRoute Route Prefix contain a path

2020-03-25 11:44发布

问题:

Currently I use this:

RouteTable.Routes.Add(new ServiceRoute("API", new WebServiceHostFactory(),typeof(MySite.Web.MyServiceV1)));

To make this url point to the MyServiceV1.SVC MySite.com/API


I want to use a Prefix which contains a / in it but it doesn't seem to work.

RouteTable.Routes.Add(new ServiceRoute("API/V2", new WebServiceHostFactory(),typeof(MySite.Web.MyServiceV2)));

Is there a better way to represent this instead of having to do "APIV2" ? I am using .Net 4.0

回答1:

I totally forgot that the order you register routes mattered. This works:

RouteTable.Routes.Add(new ServiceRoute("API/V2/", new WebServiceHostFactory(),typeof(MySite.Web.MyServiceV2)))

RouteTable.Routes.Add(new ServiceRoute("API/", new WebServiceHostFactory(),typeof(MySite.Web.MyServiceV1)));