Keep more of the url for requests SwaggerWcf

544 Views Asked by At

My WCF service is locally hosted like this:
localhost/service.svc
On the server it's hosted like this:
servername/extra/service.svc
When making a request SwaggerWcf uses the base path and adds the configered elements: localhost/user/parameter
But it should be:
localhost/extra/user/parameter
So I need WCF to not just use the hostname, but also a little more of the url.
I could add it to the SwaggerWcf configuration, which is user and could be extra/user. But then it won't work locally anymore.

I've tried adding a Config class that could read configuration attributes statically:

using System.Configuration;

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

But when I try to use this:

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

It still produces the same error:

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

How can this be done dynamically? Then it can be different for different environments.

1

There are 1 best solutions below

2
Abel Silva On BEST ANSWER

Currently there is no way to do it But I'll take a look into this later today

Probably the best way is allowing to override it using 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>