【发布时间】:2012-01-05 07:58:26
【问题描述】:
我一直在尝试弄清楚为什么这个 UriTemplate 不能作为 WCF 服务的一部分工作并且似乎无法到达任何地方:
[WebGet(UriTemplate="api/1.0/version")]
string GetVersion();
快速测试表明 UrlTemplateTable 匹配良好(输出为 '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());
}
点不是 URL 中的非法字符,RequestPathInvalidCharacters 不排除它,没有可能干扰的重写规则。在它的文档中也找不到任何东西。
虽然有一个明显的解决方法,但不要使用模板中的点,但我很好奇为什么它会失败并显示“HTTP 404/找不到资源”。
【问题讨论】: