【问题标题】:WCF Web Api optional parameters in UriTemplateUriTemplate 中的 WCF Web Api 可选参数
【发布时间】:2012-01-24 16:59:31
【问题描述】:

如何在 WCF Web Api 的 UriTemplate 中声明可选参数? 例如:

[WebGet(UriTemplate = "?culture={culture}")]
HttpResponseMessage<IEnumerable<Contact>> GetAll();

我需要文化作为可选参数。如果文化没有通过,我想收到 null 对于那个参数。

PS。我不想使用具有不同 UriTemplate 的多个 GetAll 方法创建解决方案...

【问题讨论】:

    标签: wcf rest wcf-web-api uritemplate webget


    【解决方案1】:

    使用以下方法声明文化参数将为空

    [WebGet(UriTemplate = "?culture={culture}")]
    HttpResponseMessage<IEnumerable<Contact>> GetAll(string culture);
    

    【讨论】:

      猜你喜欢
      • 2013-06-19
      • 2011-02-27
      • 1970-01-01
      • 1970-01-01
      • 2016-11-09
      • 2013-07-24
      • 1970-01-01
      • 2013-04-16
      • 2012-04-04
      相关资源
      最近更新 更多