Why does the WCF 3.5 REST Starter Kit do this?

Posted by Brandon on Stack Overflow See other posts from Stack Overflow or by Brandon
Published on 2010-04-20T12:59:03Z Indexed on 2010/04/20 13:03 UTC
Read the original article Hit count: 202

Filed under:
|
|
|

I am setting up a REST endpoint that looks like the following:

[WebInvoke(Method = "POST", UriTemplate = "?format=json", BodyStyle = WebMessageBodyStyle.WrappedRequest, ResponseFormat = WebMessageFormat.Json)]

and

[WebInvoke(Method = "DELETE", UriTemplate = "?token={token}&format=json", ResponseFormat = WebMessageFormat.Json)]

The above throws the following error:

UriTemplateTable does not support '?format=json' and '?token={token}&format=json' since they are not equivalent, but cannot be disambiguated because they have equivalent paths and the same common literal values for the query string. See the documentation for UriTemplateTable for more detail.

I am not an expert at WCF, but I would imagine that it should map first by the HTTP Method and then by the URI Template. It appears to be backwards. If both of my URI templates are:

?token={token}&format=json

This works because they are equivalent and it then appears to look at the HTTP Method where one is POST and the other is DELETE.

Is REST supposed to work this way? Why are the URI Template Tables not being sorted first by HTTP Method and then by URI Template? This can cause some serious frustrations when 1 HTTP Method requires a parameter and another does not, or if I want to do optional parameters (e.g. if the 'format' parameter is not passed, default to XML).

© Stack Overflow or respective owner

Related posts about c#

Related posts about wcf