Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3270732
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T18:39:58+00:00 2026-05-17T18:39:58+00:00

I have a WCF REST 4.0 project based on the the WCF REST Service

  • 0

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 without trailing slashes. For example:

  1. CarService.cs
    • http://www.domain.com/cars – GET returns a list of all cars
    • http://www.domain.com/cars/123 – GET returns a single car with ID 123
  2. TruckService.cs
    • http://www.domain.com/trucks – GET returns a list of all trucks
    • http://www.domain.com/trucks/456 – GET returns a single truck with ID 456

I look at the above URLs as resource requests (not directories), which is why I don’t think trailing slashes are appropriate here.

Unfortunately, I can’t seem to get the behavior I want because I am always redirected to /cars/ and /trucks/ with a trailing slash.

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:

// Global.asax.cs
RouteTable.Routes.Add(new ServiceRoute("cars", new WebServiceHostFactory(), typeof(CarService)));

// CarService.cs
[WebGet(UriTemplate = "")]
public List<Car> GetCollection()
{
    return DataContext.GetAllCars();
}

Note that MVC does not work this way. With the MapRoute method I can route requests directly to http://www.domain.com/about without a redirect to /about/. How can I get the same behavior in WCF REST 4.0?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-17T18:39:58+00:00Added an answer on May 17, 2026 at 6:39 pm

    The primary issue that you’re running into is that the current version of WCF REST causes a 307 redirect (to the “/”) when you have an empty string for the UriTemplate in your WebGet attribute. As far as I know, there is no getting around this in the current version.

    However, there are a couple of “middle ground” solution to your problem given that you want a solution that 1) allows you to differentiate services, and 2) have (relatively) short URIs.

    First Solution
    You can put this in your global.asax file (per this example). You can do a service route for each service:

    RouteTable.Routes.Add(new ServiceRoute("cars", new WebServiceHostFactory(), typeof(CarService)));
    RouteTable.Routes.Add(new ServiceRoute("trucks", new WebServiceHostFactory(), typeof(TruckService)));
    

    At this point you can populate your UriTemplate in each service:

    [WebGet(UriTemplate = "all")]
    CarPool GetAllCars();
    
    [WebGet(UriTemplate = "{carName}")]
    Car GetCar(string carName);
    

    This will allow you URIs of:

    www.domain.com/cars/all
    www.domain.com/cars/123 or www.domain.com/cars/honda
    

    similarly for trucks:

    www.domain.com/trucks/all
    www.domain.com/trucks/123 or www.domain.com/trucks/ford
    

    Second Solution
    Use the service host from the REST Starter Kit (i.e., the WebServiceHost2Factory).

    RouteTable.Routes.Add(new ServiceRoute("cars", new WebServiceHost2Factory(), typeof(CarService)));
    

    This does not result in a 307 redirect when using the URIs that you’re attempting to use above and thus, gives you exactly what you need. Though I realize that feels a little weird using that service host factory rather than the one that ships with WCF 4.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a WCF REST service that exposes a couple dozen objects and based
I have created a WCF REST style service in my project. In development I
I have a C# WCF REST Service which allows the addition of a bookmark,
I have a REST service consumed by a .Net WCF client. When an error
I have WCF endpoint exposed as defined bellow, <service name=MyApp.Server.Endpoint.Orange behaviorConfiguration=MyTio.Server.Endpoint.OrangeBehavior> <endpoint address= binding=basicHttpBinding
I am new to WCF and created a simple REST service to accept an
I have a WCF Rest service: [WebHelp(Comment = Sample description for GetData)] [WebInvoke(Method=POST, UriTemplate
I have a WCF REST Service which accepts a JSON string One of the
I have trying to design a REST service in .NET 3.5 with WCF REST
I am working on a WCF REST service, and in the service I have

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.