我想创建两个基于URI中的查询字符串参数而变化的Rest方法.
喜欢
[WebGet(UriTemplate = "Guest/{guestId}?day={day}&type={type}")]
[OperationContract(Name = "GetDetailByDayAndActivity")]
public GuestDetail GetDetail(string guestId, DateTime day, string type)
[WebGet(UriTemplate = "Guest/{guestId}?day={day}")]
public GuestDetail GetDetail(string guestId, DateTime day)
Run Code Online (Sandbox Code Playgroud)
这给出了错误:
"Operation 'GetDetailByDayAndActivity' in contract 'IRestService' has a UriTemplate that expects a parameter named 'TYPE', but there is no input parameter with that name on the operation. "
访问仅具有day参数的方法时: http://testserver/GuestService/Guest/0?day=2011-10-20
怎么能实现这一目标?
找出导致此错误的原因.接口中的参数名称不同.URI中使用的名称必须与接口中的名称匹配.
此外,如果我们使用查询字符串,则无需定义单独的方法.单个方法可以工作,在这种情况下,其他参数将具有空值.