4

I've been trying for a while now to figure out why this UriTemplate does not work as part of a WCF service and can't seem to get anywhere:

[WebGet(UriTemplate="api/1.0/version")]
string GetVersion();

A quick test shows that UrlTemplateTable matches it fine (output is 'api/1.0/version'):

static void Main(string[] args)
{
    Uri prefix = new Uri("http://localhost/");
    System.UriTemplateTable table = new System.UriTemplateTable(prefix);
    table.KeyValuePairs.Add(new KeyValuePair<UriTemplate, Object>(new UriTemplate("api/1.0/version"), "a"));
    table.KeyValuePairs.Add(new KeyValuePair<UriTemplate, Object>(new UriTemplate("api/2.0/version"), "b"));
    table.KeyValuePairs.Add(new KeyValuePair<UriTemplate, Object>(new UriTemplate("api/version"), "c"));

    Uri uri = new Uri("http://localhost/api/1.0/version");
    UriTemplateMatch match = table.MatchSingle(uri);
    Console.WriteLine("{0}", match.Template.ToString());
}

The dot is not an illegal character in URLs, RequestPathInvalidCharacters does not exclude it, there are no rewrite rules in place that could interfere. Couldn't find anything in the documentation on it either.

While there is an obvious workaround, not use the dot in the template, I'm curious as to why it fails with 'HTTP 404/The resource cannot be found'.

Chris
  • 1,825
  • 1
  • 12
  • 12

1 Answers1

3

I ran into the same issue before. I realized it was a limitation in IIS, and nothing to do with WCF. When IIS initially intercepts the request assumes the value following the . represents an extension, so it tries to find a managed handler for that extension. Since it does not find any, it just throws a 404.

Regards Pablo.

Pablo Cibraro
  • 3,769
  • 3
  • 25
  • 17
  • Very good point, I was looking for an answer in the wrong place! Searching for IIS and a bunch of info comes up, [more pointed SO question here](http://stackoverflow.com/questions/294495/semantic-urls-with-dots-in-net). – Chris Jan 06 '12 at 01:07
  • Very good point. Worth many times more than the scored you got! I was trying to make a web service URL look like a file, thus ending with .something ! – Thibault D. Jun 12 '14 at 11:19
  • is there any other character invalid? – Ed_ May 13 '16 at 19:45