I have an operation contract in an existing WCF service. Now I am extending it for WCF REST api and I am getting a lot of errors, the last one in the service is around parameters. My code is as below:
[OperationContract(Name = "Messages", IsOneWay = true)]
[WebInvoke(Method = "GET",
UriTemplate = "/Messages/?id={id}&fileId={fileId}",
ResponseFormat = WebMessageFormat.Xml,
BodyStyle = WebMessageBodyStyle.Wrapped)]
[Description("Inbound Message")]
void Messages(Guid id, int fileId);
I am getting the error:
The UriTemplate '/Messages/?id={id}&fileId={fileId}' is not valid; each portion of the query string must be of the form 'name=value', when value cannot be a compound segment. See the documentation for UriTemplate for more details.*
Please suggest what am I missing in the uritemplate?
You need to remove /
before ?
from UriTemplate
and change id
parameter to string.
[OperationContract(Name = "Messages", IsOneWay = true)]
[WebInvoke(Method = "GET",
UriTemplate = "/Messages?id={id}&fileId={fileId}",
ResponseFormat = WebMessageFormat.Xml,
BodyStyle = WebMessageBodyStyle.Wrapped)]
[Description("Inbound Message")]
void Messages(string id, int fileId);
See also: UriTemplate and UriTemplateTable
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.