休息的方法各不相同通过查询字符串参数 [英] Rest Methods that vary by query string parameters

查看:121
本文介绍了休息的方法各不相同通过查询字符串参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要创建基于URI中的查询字符串参数而异其余两个方法。

I want to create two Rest methods that vary based on the query string parameter in the URI.

喜欢

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

这给出了错误:

在承包经营GetDetailByDayAndActivity'IRestService'的UriTemplate希望获得名为类型参数,但对操作的名称的输入参数。

当访问具有只喜欢白天参数的方法:的http:// TESTSERVER / GuestService /客户/ 0天= 2011-10-20

When accessing the method that has only the day parameter like: http://testserver/GuestService/Guest/0?day=2011-10-20

如何才能实现这一目标?

How can this be achieved?

推荐答案

想通了这个错误的原因。 在接口参数的名称有所不同。在URI中使用的名称必须与当时的接口名称匹配。

Figured out the cause of this error. The name of parameter in the Interface was different. The name used in the URI must match with then name in interface.

而且,也没有必要,如果我们使用查询串以限定单独的方法。单方法将工作,在这种情况下,其他参数将具有空值。

Moreover, there is no need to define separate methods if we are using query string. Single method would work, in this case other parameters will have null values.

这篇关于休息的方法各不相同通过查询字符串参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆