none
Using "MyCollection/{id}" in [WebGet(UriTemplate)] brings message error

    Question

  • When trying to add [WebGet(UriTemplate="MyCollection/{id}")], calling the URL ....svc/MyCollection/1 does not work and throws the following message : "Since the segment '...' refers to a collection, this must be the last segment in the request URI. All intermediate segments must refer to a single resource."

    Everything works fine if I use MyCollection?id={id} instead. Is there a particulary reason for this behaviour ?

    Thanks in advance for any help

    Monday, March 05, 2012 5:44 PM

Answers

  • Assuming you're adding the UriTemplate to a service operation on a WCF Data Services service (DataService<T> derived class), right?

    In that case this behavior is expected. WCF DS doesn't recognize the UriTemplate, it simply ignores it. The default (and only) way to pass parameters to service operations is to pass them as query options. So if you method has a parameter called "id", then the query option ?id=value is the right way to pass it in.

    Thanks,


    Vitek Karas [MSFT]

    Monday, March 05, 2012 10:14 PM

All replies

  • Assuming you're adding the UriTemplate to a service operation on a WCF Data Services service (DataService<T> derived class), right?

    In that case this behavior is expected. WCF DS doesn't recognize the UriTemplate, it simply ignores it. The default (and only) way to pass parameters to service operations is to pass them as query options. So if you method has a parameter called "id", then the query option ?id=value is the right way to pass it in.

    Thanks,


    Vitek Karas [MSFT]

    Monday, March 05, 2012 10:14 PM
  • Hi, Vitek

    Thanks for your answer. Do you know of a workaround for this ? I tried adding an [OperationContract], but this is not possible to declare the class as a [ServiceContract], as the inheritance from DataService<> makes it impossible...

    I am thinking about URL rewriting, or maybe an Http handler to partly process the request before redirecting it to WCF collections? This kind of request seems quite current in REST, so I would really like to make it available, even if this means adding a layer of code on top of WCF Data Services. Is there a way you would recommend / warn against ?

    Cheers,

    JP

    Tuesday, March 06, 2012 8:51 AM