【发布时间】:2010-05-03 18:07:36
【问题描述】:
我有几个这样的 RESTful 端点:
System.Security.Role.svc
System.Security.User.svc
etc.
这是一个命名空间,所以我们的 RESTful URL 看起来像:
/rest/{class namespace}/{actions}
当我的端点中有多个句点时,我尝试了一些示例来删除 SVC 扩展,但是,似乎没有任何效果。
我已经使用 WCF REST Contrib 包 (http://wcfrestcontrib.codeplex.com/)、此示例 (http://www.west-wind.com/weblog/posts/570695.aspx) 和另一个 StackOverflow 帖子 (How to remove the ".svc" extension in RESTful WCF service?) 进行了测试。
当我的端点是这样的时候,这很有效:
Echo.svc
它将正确删除 SVC 扩展。
关于如何处理端点名称中有多个句点的端点有什么想法吗?
编辑: 经过进一步的测试,我发现它失败了,因为每当你这样做时:
string path = HttpContext.Current.Request.AppRelativeCurrentExecutionFilePath;
如果端点包含多个句点,它将剥离端点之后的所有内容,导致所有标准 IHttpModule 失败。
例子:
如果我调用http://localhost/services/Echo/test,我的相对应用文件路径的返回值为:
~/echo/test
但是,如果我以http://localhost/services/System.Security.User/test 进行调用,那么我的相对应用程序文件路径的返回值为:
~/system.security.user
在那种情况下,我最后错过了“/test”。
【问题讨论】: