2011-07-07 63 views
0

lyDefinition资源宁静WCF默认值

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

的我怎样才能使最后的两个参数可选?即,我想底部的三个电话的工作

"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" 

但只有最后一次通话的作品,剩下的给缺少的参数错误。

感谢 看涨

+0

什么是您的.NET framework版本? [我之前测试过](http://stackoverflow.com/questions/5781342/wcf-and-optional-parameters)用'UriTemplate'的查询字符串中的'string'和'int'参数,它工作。 –

回答

0

我相信你这样做你重载方法相同的方式调用:

[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

我试过了,但它不起作用。我相信它给出了一个错误,不能有多个方法与uripath“getbydaterange”相关联。 – Bullish

+0

@Bullish:糟糕,更改(或者更确切地说)添加** Name **参数到操作合同。例如'[OperationContract(Name =“GetMyObjectsByInsId”)]','[OperationContract(Name =“GetMyObjectsByInsIdAndDate”)]'&'[OperationContract(Name =“GetMyObjectsByInsIdAndDateRange”)]' –

+0

是的,不是我想要的,但它是最接近的。 理想情况下,我想要一个方法,并将NULL传递给未传入的参数。 – Bullish