views:

38

answers:

1

I have a bunch of self-hosted WCF services. Everything's working fine but I'm look for ways to normalize/simplify the resultant config. I've simplified it as much as possible, but I'm still not happy. Currently, my config looks like this:

<system.serviceModel>
    <bindings>
        <netTcpBinding>
            <binding name="BindingConfiguration" ...>
                ...
            </binding>
        </netTcpBinding>
    </bindings>

    <behaviors>
        <serviceBehaviors>
            <behavior name="ServiceBehavior">
                 ...
            </behavior>
        </serviceBehaviors>
    </behaviors>

    <services>
        <service behaviorConfiguration="ServiceBehavior" name="Name1">
            <endpoint address="net.tcp://localhost:8080/name1" binding="netTcpBinding" bindingConfiguration="BindingConfiguration" contract="Contract1">
                <identity>
                    <dns value="localhost" />
                </identity>
            </endpoint>
        </service>
        <service behaviorConfiguration="ServiceBehavior" name="Name2">
            <endpoint address="net.tcp://localhost:8080/name2" binding="netTcpBinding" bindingConfiguration="BindingConfiguration" contract="Contract2">
                <identity>
                    <dns value="localhost" />
                </identity>
            </endpoint>
        </service>
        ...
    </services>
</system.serviceModel>

In all, I have 6 services so it's repetitive. Ideally, I'd like:

  • To specify "localhost:8080" only once and share between all services, and only specify the difference ("name1" or "name2")
  • Specify the identity information only once and share between all service definitions

To my first point, I've aware of base addresses, but that only works at the service level, not across separate services. To my second point, I've tried moving the identity information into an endpoint behavior, but that doesn't appear to be supported.

Is there anything I can do to simplify this config? Or is my only option to switch to a code-based configuration approach?

+1  A: 

Unfortunately, as you noticed yourself - the base address concept is only on a per-service level - so if you have lots of endpoints for a given service, then you can use it.

The only option you really would have is to use some other means of configuring your base address, and then use that to create the service endpoints in code. If you self-host your service, you could do this in your host code, before you call ServiceHost.Open() - if you host in IIS, you would have to create your own custom ServiceHostFactory which does all this setup, and then use that custom service host factory to create your service hosts in IIS.

Both is doable with a manageable effort - question is whether that's worth the trouble for you, but we can't decide that in your place ...

marc_s
Bummer - was afraid of that. Thanks anyway.
Kent Boogaart