用于RESTful资源的WCF UriTemplate

时间:2010-12-28 22:22:34

标签: .net wcf c#-4.0

As mentioned in 2009,WCF无法区分以下网址以返回用户列表和特定用户:

/users 
/users/{id}

WCF4仍然如此吗?

2 个答案:

答案 0 :(得分:3)

大卫的答案很棒,但我会用:

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

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

答案 1 :(得分:1)

你现在可以这样做:

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

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

重要的是,OperationContract必须具有Name =属性,每个操作都有不同的名称。