Dmitry Sadakov
Dmitry Sadakov

Reputation: 2158

WCF UriTemplate for RESTful resource

As mentioned in 2009, WCF could not differentiate the following urls to return a list of Users and a specific User:

/users 
/users/{id}

Is this still the case with WCF4?

Upvotes: 1

Views: 2908

Answers (2)

NovaJoe
NovaJoe

Reputation: 4625

David's answer is great, but I'd use:

[OperationContract(Name="Op1")]
[WebGet(UriTemplate = "DoWork/")]
int[] DoWork();

[OperationContract(Name = "Op2")]
[WebGet(UriTemplate = "DoWork/{id}")]
int[] DoWork(string id);

Upvotes: 3

David
David

Reputation: 2795

You can do this now:

[OperationContract(Name="Op1")]
[WebInvoke(Method= "GET", UriTemplate = "DoWork/")]
int[] DoWork();

[OperationContract(Name = "Op2")]
[WebInvoke(Method = "GET", UriTemplate = "DoWork/{id}")]
int[] DoWork(string id);

The important thing is that the OperationContract must have the Name= property with different names for each operation.

Upvotes: 1

Related Questions