【问题标题】:WCF REST url prefix attributeWCF REST url 前缀属性
【发布时间】:2015-04-25 00:11:43
【问题描述】:

我正在开发 WCF REST 服务。我有合同:

[ServiceContract]
public interface IContract
{
    [OperationContract]
    [WebInvoke(Method = "GET",
        ResponseFormat = WebMessageFormat.Json,
        RequestFormat = WebMessageFormat.Json,
        UriTemplate = "/somemethod/{param1}")]
    SomeResult SomeMethod(int param1) { ... }

    /*

    More methods...

    */
}

有没有办法为给定合约的所有方法配置一个公共 url 前缀。可能类似于 Web API [RoutePrefix("...")] 属性?

【问题讨论】:

  • Common Url 前缀是什么意思?
  • @Tommassiov 例如,我希望我的所有网址都从“/users/”开始。

标签: c# .net wcf asp.net-web-api wcf-rest


【解决方案1】:

老实说,我不确定这是否可能,但也许从 WebInvoke 派生您自己的属性会有所帮助?然后,您可以在内部将前缀添加到将设置的 UriTemplate 的任何内容。

但我从来没有这样尝试过......

【讨论】:

    【解决方案2】:

    试试这样-

    UriTemplate = "/users/somemethod/{param1}"
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-09-07
      • 1970-01-01
      • 2020-01-27
      • 2013-04-14
      • 2015-01-24
      • 1970-01-01
      相关资源
      最近更新 更多