1

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.

A9S6
  • 6,575
  • 10
  • 50
  • 82

1 Answers1

1

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.
enter image description here
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.

Abraham Qian
  • 7,117
  • 1
  • 8
  • 22
  • 1
    Thanks. There was problem with my code configuring its own custom host for CORS and replacing the variables with a wildcard char – A9S6 Apr 22 '20 at 04:44