是否有可能“过载"? uritemplates? [英] Is it possible to have "overloaded" uritemplates?

查看:100
本文介绍了是否有可能“过载"? uritemplates?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

        [OperationContract]
    [WebGet(UriTemplate = "/searchresults/{searchTerm}/{searchType}", ResponseFormat = WebMessageFormat.Xml, RequestFormat = WebMessageFormat.Xml, BodyStyle = WebMessageBodyStyle.Bare)]
    Message GetSearchResults(string searchTerm, string searchType);

    [OperationContract]
    [WebGet(UriTemplate = "/searchresults/{searchTerm}", ResponseFormat = WebMessageFormat.Xml, RequestFormat = WebMessageFormat.Xml, BodyStyle = WebMessageBodyStyle.Bare)]
    Message GetSearchResults(string searchTerm);

这是可能的-否则,有人可以建议另一种方法吗?

Is this possible - if not, can someone suggest an alternative?

推荐答案

我发现这是最适合我的解决方案:

I've found that this was the best solution for me:

    [OperationContract(Name = "SearchresultsWithSearchType")]
    [WebGet(UriTemplate = "/searchresults/{searchTerm}/{searchType=null}", 
    ResponseFormat = WebMessageFormat.Xml)]
    Message GetSearchResults(string searchTerm, string searchType);


    [OperationContract(Name = "SearchresultsWithoutSearchType")]
    [WebGet(UriTemplate = "/searchresults/{searchTerm}", 
    ResponseFormat = WebMessageFormat.Xml)]
    Message GetSearchResults(string searchTerm);

此匹配项:

"http://myservice/searchresults/mysearchterm"

"http://myservice/searchresults/mysearchterm/"

"http://myservice/searchresults/mysearchterm/mysearchtype"

这篇关于是否有可能“过载"? uritemplates?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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