[英]Is "/literal/{param}/literal" a valid url template for a WCF restful service
I am trying to add a new endpoint to a WCF based REST service with the following URL template:我正在尝试使用以下 URL 模板向基于 WCF 的 REST 服务添加一个新端点:
/books/{bookId}/pdf
but it gives an error saying:但它给出了一个错误说:
The UriTemplate '
/books/*/pdf
' is not valid;UriTemplate“
/books/*/pdf
”无效; the wildcard ('*') cannot appear in a variable name or literal, unless as a construct for a wildcard segment.通配符 ('*') 不能出现在变量名或文字中,除非作为通配符段的构造。 Note that a wildcard segment, either a literal or a variable, is valid only as the last path segment in the template;
请注意,通配符段(文字或变量)仅作为模板中的最后一个路径段有效; the wildcard can appear only once.
通配符只能出现一次。 See the documentation for UriTemplate for more details.'
有关更多详细信息,请参阅 UriTemplate 的文档。
Here's the service contract:这是服务合同:
[OperationContract]
[WebInvoke(UriTemplate = "/books/{bookId}/pdf", Method = "POST")]
Message GetBookPDF(string bookId);
Is this a limitation that the variable is only valid as the last part of the url?这是变量仅作为 url 的最后一部分有效的限制吗? I couldn't find any link that confirms that.
我找不到任何链接来证实这一点。
I am sure that the variable needn't configured in the last part of the URL.我确信在 URL 的最后一部分不需要配置变量。
My service contract我的服务合同
public interface ITestService
{
[OperationContract]
[WebInvoke(Method ="POST",UriTemplate ="/books/{id}/pdf")]
string Test(string id);
}
Result.结果。
Please have a look at this link.请查看此链接。
https://stackoverflow.com/questions/13956889/in-wcf-can-i-have-a-wildcard-character-in-a-literal-segment-of-my-uritemplate https://stackoverflow.com/questions/13956889/in-wcf-can-i-have-a-wildcard-character-in-a-literal-segment-of-my-uritemplate
The most likely scenario is that the UriTemplate can match multiple OperationContract, thus the error happened.最有可能的情况是UriTemplate 可以匹配多个OperationContract,从而发生错误。
Feel free to let me know if the problem still exists.如果问题仍然存在,请随时告诉我。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.