URI模板中的可选参数 [英] Optional Parameters in URI Template

查看:105
本文介绍了URI模板中的可选参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我已经开发了WCF Web服务,并希望在WebGet方法的URI模板中提供可选的查询字符串参数. 在网上看到它不被支持.有没有解决的办法.如果您有任何想法,请与我们分享.

预先感谢

Hi,

I have developed a WCF webservice and want to give optional query string parameters in the URI Template of WebGet method.
Saw in net that its not supported. Is there any work around for this. Kindly share if you have any ideas.

Thanks in advance

推荐答案

是的,我们可以解决可选参数.

参见下面的代码,
如果您拨打

http://< uri>/get-它将调用GetAllertion方法
http://< uri>/get/12-它将使用参数alue 12调用GetAPerson方法.

因此这些URL充当可选参数
Yes, We can have work around for optional parameter.

See the below code,
if you call

http://<uri>/get - It will call the GetAllertion method
http://<uri>/get/12 - It will call the GetAPerson method with parameter alue 12

So these URL act as optional paramter
//Get Operation
[OperationContract]
[WebGet(UriTemplate = "get" )]
List<person> GetAllPerson();
[OperationContract]
[WebGet(UriTemplate = "get/{id}")]
Person GetAPerson(string id);</person>



让我知道是否对您有帮助.

Artha



Let me know if it is helps to you.

Artha


Artha,

可以使用上面提到的方法,但是如果我们有更多的参数,那么它是不可行的.假设有5个参数,那么我们需要编写25个函数,这不是一个好主意.您对此标准有其他选择吗?

感谢您的答复.
Hi Artha,

The above mentioned method can be used but its not feasible if we have more number of parameters. Suppose say, there are 5 parameters then we need to write 25 functions which is not a good idea. Do you have any alternative for this criteria?

Thanks for the reply.


这篇关于URI模板中的可选参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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