URL Trailing Slash: subtle difference between Web API and WCF Rest

Just found an interesting difference between Web API and WCF Rest when you supply a URL with a trailing slash, e.g. http://server/path/1/.

Say you have a Web API deployed to server with a PathController. This will catch a URL with or without a trailing slash, so http://server/path/1 and http://server/path/1/ are equivalent.

On the other hand, assume you have a WCF Rest service deployed at server with a service contract containing a method decorated with [WebGet(UriTemplate=”path/{id}”)]. This will listen to http://server/service.svc/path/1 but http://server/service.svc/1/ will return an HTTP status code 404 with a message endpoint not found.

If the method is decorated with a trailing slash like [WebGet(UriTemplate=”path/{id}/”)] the service will listen to http://server/service.svc/path/1/. Trying to invoke it without the trailing slash like http://server/service.svc/path/1 will return an HTTP response code 307 Temporary Redirect with the equivalent location but including a trailing slash.

I now hope this won’t bite you as much as it bit me ;-).


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s