开发者

Restful WCF Default values

开发者 https://www.devze.com 2023-03-17 22:15 出处:网络
lyDefinition of the resource [OperationContract] [WebGet(UriTemplate = \"getbydaterange/{insId}/{startDate}/{endDate}\", ResponseFormat = WebMessageFormat.Json)]

lyDefinition of the resource

[OperationContract]
[WebGet(UriTemplate = "getbydaterange/{insId}/{startDate}/{endDate}", ResponseFormat = WebMessageFormat.Json)]
List<RestfulServiceObj> GetMyObjectsByDateRange(string insId, string startDate, string endDate);

How can i make the last two parameters optional? i.e, I want the bottom three calls 开发者_开发百科to work

"http://domain.com/service.svc/myid/"

"http://domain.com/service.svc/myid/07-07-2011"

"http://domain.com/service.svc/myid/01-01-2011/07-08-2011"

But only the last call works, the rest give a missing parameter error.

Thanks Bullish


I believe you do so that same way you overload method calls:

[OperationContract]
[WebGet(UriTemplate = "getbydaterange/{insId}", ResponseFormat = WebMessageFormat.Json)]
List<RestfulServiceObj> GetMyObjectsByDateRange(string insId);

[OperationContract]
[WebGet(UriTemplate = "getbydaterange/{insId}/{startDate}", ResponseFormat = WebMessageFormat.Json)]
List<RestfulServiceObj> GetMyObjectsByDateRange(string insId, string startDate);

[OperationContract]
[WebGet(UriTemplate = "getbydaterange/{insId}/{startDate}/{endDate}", ResponseFormat = WebMessageFormat.Json)]
List<RestfulServiceObj> GetMyObjectsByDateRange(string insId, string startDate, string endDate);
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号