简体   繁体   中英

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:

/books/{bookId}/pdf

but it gives an error saying:

The UriTemplate ' /books/*/pdf ' is not valid; 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.'

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? 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.
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
The most likely scenario is that the UriTemplate can match multiple OperationContract, thus the error happened.
Feel free to let me know if the problem still exists.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM