0

I can't seem to make WCF happy. I have 2 methods in my service, here are their Uri and method sig:

    [WebGet(UriTemplate = "/?memberID={memberID}&count={count}&pageNumber={pageNumber}&sortOrder={sortOrder}&event_ID={event_ID}&ticketids={ticketids}")]
    public InventoryResponse Get(string memberID, string count, string pageNumber, InventorySortOrder sortOrder, string event_ID, string ticketids)


    [WebGet(UriTemplate = "/?memberID={mmberID}&count={count}&pageNumber={pageNumber}&sortOrder={sortOrder}&event_ID={event_id}&ticketids={ticketids}&isTestCall=1")]
    public virtual InventoryResponse GetTest(string memberID, string count, string pageNumber, InventorySortOrder sortOrder, string event_id, string ticketids, bool isTestCall)

seems like even though on the second Uri, I added "&isTestCall=1" to the end, "&isTestCall={isTestCall}" no matter what I do I still get this error, even though I feel I've differentiated the Uri:

UriTemplateTable does not support multiple templates that have equivalent path as template '/?memberID={memberID}&count={count}&pageNumber={pageNumber}&sortOrder={sortOrder}&event_ID={event_ID}&ticketids={ticketids}' but have different query strings, where the query strings cannot all be disambiguated via literal values. See the documentation for UriTemplateTable for more detail.

PositiveGuy
  • 46,620
  • 110
  • 305
  • 471

1 Answers1

2

I'm not a WCF guru, but that error means that you cannot have a template for the same uri ("/" in your case) with different parameters.

Maybe you can go with only one function and an optional parameter?

Gusman
  • 14,905
  • 2
  • 34
  • 50
  • I need 2 functions. We are offering a temporary Test GET method. – PositiveGuy Apr 14 '14 at 00:24
  • there is an optional parameter, it's the isTestCall. And those Uris are not the same, I said I added the isTestCall to the URi which should make it different than the first pattern which is why I can't figure out why this is complaining. – PositiveGuy Apr 14 '14 at 00:25
  • 1
    I belive it's because the uri is the same, you are changing parameters, not the location of the uri, anything after ? are parameters, if you want another uri try "/test/?(yourparameters...)" – Gusman Apr 14 '14 at 01:02
  • but it's not the same, meaning I added that isTestCall which should make the Uri unique for the GetTest method – PositiveGuy Apr 14 '14 at 01:08
  • one would think if I have a completely different name (because you can't have 2 methods with the same name in WCF contracts anyway) such as Get for one Method and GetTest for another, and then both have 2 different Uri patterns (because the 2nd also has a isTestCall) one would think that's sufficient. I mean if this were ASP.NET MVC I think it would be unique in my case and I wouldn't have any issues with routes but for some reason WCF is weird – PositiveGuy Apr 14 '14 at 01:10
  • 1
    Nope, WCF uses the the Uri path to determine which function to call. It's really well explained in the error "UriTemplateTable does not support multiple templates that have equivalent path...", the key here is "path", both functions have exactly the same path ("/"), as I said, anything after "?" are parameters, not part of the path. – Gusman Apr 14 '14 at 01:16
  • yea to me that makes no sense coming from an MVC perspective. I say MVC because that's the way the rest of the world works and is probably why MS ditched WCF with ASP.NET Web API – PositiveGuy Apr 14 '14 at 01:24
  • thanks Gusman, beacause I look at it from a more standard approach (MVC) which is why I really don't like using WCF, weirdness like this and it requires you to do stuff you may not want to be doing as I don't want to really do this but oh well – PositiveGuy Apr 14 '14 at 01:25
  • Glad it helped. WCF is following the same pattern as a RESTful service where each resource has an unique path, so it is not really so weird ;) – Gusman Apr 14 '14 at 01:31
  • no totally disagree. It IS it weird and dumb by today's clean cod standards, because with the Web API and MVC routes and patterns differentiate the incoming request and what class and method it's wired to by the patternin the route and signature of your controller's method (params). This is not the same, it sucks in WCF, its old and not made for RESTful in terms of managing it in the backend restfully...and just cleanly (using overloaded methods). This is why MS was forced to move to use MVC and Web API on top of that later to get rid of WCF – PositiveGuy Aug 10 '14 at 21:33
  • and it forces you to put a bunch of logic in your ONE Get method in your .svc if you can't overload it. Lets say you have optional params. You end up having to check whether they sent in lets say paging, or date ranges in the ONE Get method and that gets messy ratehr than map certain querystring combinations to related overloads in the backend. – PositiveGuy Aug 10 '14 at 21:47
  • Interesting debate and I can accept this as a rule. But why is the exact same uritemplate allowed? eg "/user?id={id}" repeated for 2 different methods. – ianbeks Jan 09 '15 at 12:33
  • @ianbeks Well, that's the real question :D, I think because the template are parsed only on runtime and MS decided to do not throw an exception on duplicated templates, but that's only a guess. – Gusman Jan 09 '15 at 16:17