WCF UriTemplate不匹配斜杠一个字符串参数(/人的)斜杠、字符串、不匹配、参数

2023-09-03 13:51:10 作者:享受人世的糜烂

下面是该方案,我有一个WCF服务调用,它有一个字符串参数,该字符串中有斜杠(如123 / 456.xml)。我想设置这样的UriTemplate/ {文件}这样我就可以在的 http://www.example.com/File.svc/123/456.xml 而不是的 http://www.example.com/File.svc/GetFile?file=123/456.xml 。

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.

这可能与UriTemplate?

Is this possible with UriTemplate?

在我意识到,我可以建立像一个UriTemplate/ {目录} / {文件},但是这是不是一种选择,因为有一个可变数目的目录。

推荐答案

好吧,我发现MSDN上的解决方案。 UriTemplates支持通配符段基本上指的是路径的其余部分。所以,我可以指定像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.

在MSDN文档: http://msdn.microsoft.com/en-us /library/bb675245.aspx 更好的解释: http://hyperthink.net/blog/uritemplate-match/ MSDN docs: http://msdn.microsoft.com/en-us/library/bb675245.aspx Better explanation: http://hyperthink.net/blog/uritemplate-match/