4
我一直在努力了一段时间,现在要弄清楚为什么这个UriTemplate不作为WCF服务的一部分工作,似乎无法取得任何进展:WebGet UriTemplate失败点('。'/%2E)?
[WebGet(UriTemplate="api/1.0/version")]
string GetVersion();
快速测试显示,UrlTemplateTable与之匹配罚款(输出“API/1.0 /版本”):
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 /资源无法找到'。
非常好的一点,我在错误的地方寻找答案!搜索IIS和一堆信息出现,[更指出所以问题在这里](http://stackoverflow.com/questions/294495/semantic-urls-with-dots-in-net)。 – Chris 2012-01-06 01:07:40
非常好的一点。比得分你的得分多得多!我试图让Web服务URL看起来像一个文件,因此以.something结尾! – 2014-06-12 11:19:55
还有其他字符无效吗? – 2016-05-13 19:45:42