保留更多 url 用于请求 SwaggerWcf

Keep more of the url for requests SwaggerWcf

我的 WCF 服务是这样在本地托管的:
localhost/service.svc
在服务器上它是这样托管的:
servername/extra/service.svc
发出请求时,SwaggerWcf 使用基本路径并添加配置元素: localhost/user/parameter
但应该是:
localhost/extra/user/parameter
所以我需要 WCF 不仅使用主机名,还需要更多的 url.
我可以将它添加到 SwaggerWcf 配置中,它是 user 并且可能是 extra/user。但是之后它将不再在本地工作。

我尝试添加一个可以静态读取配置属性的配置 class:

using System.Configuration;

namespace Project
{
    public static class Config
    {
        public static readonly string SwaggerWcfRequestPath = ConfigurationManager.AppSettings["SwaggerWcf.RequestPath"] ?? "/user";
    }
}

但是当我尝试使用 this 时:

[SwaggerWcf(Config.SwaggerWcfRequestPath)]
public class Service: IService

它仍然产生相同的错误:

Error   46  An attribute argument must be a constant expression, typeof expression or array creation expression of an attribute parameter type.

如何动态地做到这一点?那么对于不同的环境它可以是不同的。

暂时没有办法 但我会在今天晚些时候研究一下

可能最好的方法是允许使用 Web.config

覆盖它
  <configSections>
    <section name="swaggerwcf" type="SwaggerWcf.Configuration.SwaggerWcfSection, SwaggerWcf"/>
  </configSections>
  <swaggerwcf>
    <settings>
      <setting name="Host" value="www.msampleservice.com"/>
      <setting name="BasePath" value="/myserviceapi"/>
    </settings>
  </swaggerwcf>