views:

63

answers:

1

Hello,

I'm developing an n-tier smart client application. The client part of the application is split into two tiers. An interface application and client business lib that retrieves and serves data to the interface. The data is supplied via a collection of WCF services net.tcp and http depending on the client connectivity.

My problem is that the interface knows nothing of the wcf services (as we want) the configurations system.serviceModel binding info is stored within the config for the lib rather than the exe. Unless I copy the system.serviceModel section to the exe config the application cannot find the endpoints.

So I could create some Pre-Build event that copies the app.config file:

attrib -r "$(ProjectDir)app.config" copy "$(SolutionDir)Domain\Client\app.config" "$(ProjectDir)"

but this, frankly, is crap (its a straight copy not merge) and I want a better way of working it.... Any ideas? Thanks

+4  A: 

Have you tried importing the relevant sections from an external config file using the configSource element? The last answer in this discussion provides a solution that may work for you.

Quoted from that discussion:

<!-- WCF Configuration Mappings in app.config -->
<system.serviceModel>
  <bindings configSource=".\CommonConfig\ServiceBindings.config" />
  <client configSource=".\CommonConfig\ServiceClient.config" />
</system.serviceModel>

ServiceBindings.config:

<?xml version="1.0" encoding="utf-8" ?>
<bindings>
  <netTcpBinding>
    <binding ... />
  </netTcpBinding>
</bindings>

ServiceClient.config (shortened):

<?xml version="1.0" encoding="utf-8" ?>
<client>
  <endpoint ...>
      ...
  </endpoint>
</client>
Fredrik Mörk
+1 excellent answer - that way, a large portion of the config can also be shared between the server and client; after all, both sides need to agree on bindings, (some) behaviors, and endpoint addresses
marc_s
Thanks Fredrik! Great answer!
jaimie