WCF UriTemplate 不会与带有斜杠 (/'s) 的单个字符串参数匹配

发布于 2024-08-24 16:24:14 字数 522 浏览 1 评论 0原文

这是一种场景,我有一个 WCF 服务调用,它采用一个字符串参数,并且该字符串中包含斜杠(例如“123/456.xml”)。我想设置一个像“/{file}”这样的 UriTemplate,以便我可以访问 http://www.example.com/File.svc/123/456.xml 而不是 http://www.example.com/File.svc/GetFile?file=123/456.xml

这可以用 UriTemplate 实现吗?

  • 我意识到我可以设置一个像“/{directory}/{file}”这样的 UriTemplate,但这不是一个选项,因为目录的数量是可变的。

Here is the scenario, I have a WCF service call that takes one string parameter and that string has slashes in it (e.g. "123/456.xml"). I want to setup a UriTemplate like this "/{file}" so that I can access the method at http://www.example.com/File.svc/123/456.xml rather than http://www.example.com/File.svc/GetFile?file=123/456.xml.

Is this possible with UriTemplate?

  • I realize that I could setup a UriTemplate like "/{directory}/{file}" but that is not an option because there is a variable number of directories.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

鹿港巷口少年归 2024-08-31 16:24:14

好吧,我在MSDN上找到了解决方案。 UriTemplates 支持通配符段,这基本上意味着路径的其余部分。因此,我可以指定一个像“/{*file}”这样的 UriTemplate,它将按预期工作。

Alright, I found a solution on MSDN. UriTemplates support wildcard segments which basically mean the rest of the path. So I can specify a UriTemplate like "/{*file}" and it will work as expected.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文