Note that there are some explanatory texts on larger screens.

plurals
  1. POSimple URL routes in WCF Rest 4.0 without trailing slash
    primarykey
    data
    text
    <p>I have a WCF REST 4.0 project based on the the WCF REST Service Template 40(CS). I'd like to expose simple service endpoint URLs <em>without</em> trailing slashes. For example:</p> <ol> <li>CarService.cs <ul> <li><a href="http://www.domain.com/cars">http://www.domain.com/cars</a> - GET returns a list of all cars</li> <li><a href="http://www.domain.com/cars/123">http://www.domain.com/cars/123</a> - GET returns a single car with ID 123</li> </ul></li> <li>TruckService.cs <ul> <li><a href="http://www.domain.com/trucks">http://www.domain.com/trucks</a> - GET returns a list of all trucks</li> <li><a href="http://www.domain.com/trucks/456">http://www.domain.com/trucks/456</a> - GET returns a single truck with ID 456</li> </ul></li> </ol> <p>I look at the above URLs as resource requests (not directories), which is why I don't think trailing slashes are appropriate here.</p> <p>Unfortunately, I can't seem to get the behavior I want because I am always redirected to /cars/ and /trucks/ <em>with</em> a trailing slash.</p> <p>Here's how I've defined the "cars" route and service method - note that I have not included any slashes in any of the route or URI template definitions:</p> <pre><code>// Global.asax.cs RouteTable.Routes.Add(new ServiceRoute("cars", new WebServiceHostFactory(), typeof(CarService))); // CarService.cs [WebGet(UriTemplate = "")] public List&lt;Car&gt; GetCollection() { return DataContext.GetAllCars(); } </code></pre> <p>Note that MVC does not work this way. With the MapRoute method I can route requests directly to <a href="http://www.domain.com/about">http://www.domain.com/about</a> without a redirect to /about/. How can I get the same behavior in WCF REST 4.0?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload