简体   繁体   中英

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?

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);

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.

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM