Target external file for WCF reference from web.config.

I have an ASP.Net project that uses an external config file for application settings.  The web.config file has the following node to do this:
<appSettings file="C:\MyDirectory\appSettings.config">
</appSettings>

In the above scenario all of the key/value settings for the website are in that appSettings.config file, using the following syntax:
<appSettings>
  <add key="MyKey" value="MyValue"/>
</appSettings>

The reason the site is set up this way is so that when we move it from various environments (Dev/Test/Prod) we are not required to change the web.config file each time that happens.  The config files are in the same directory on each hosting server.

Now we've added a reference to a WCF which appears in web.config.  In this scenario we have different WCF environments as well (Dev/Test/Prod).  Is there a way to have the WCF reference target an external configuration file as well?  This is what the reference looks like which was generated by Visual Studio 2008 when I added the reference.

<system.serviceModel>
    <bindings>
        <wsHttpBinding>...</wsHttpBinding>
    </bindings>
    <client>
        <endpoint address="http://MyWCFReference">
            <identity>
                <dns value="MyWCFReference"/>
            </identity>
        </endpoint>
    </client>
</system.serviceModel>

What I want to do is store those 2 entries for MyWCFReference in an external file.  Since it isn't in the <appSettings> node, where can I put the reference?  Would it work to add a "file=" attribute to the <client> node above, like so?

    <client file="C:\MyDirectory\wcfSettings.config">
    </client>

Then put this into the wcfSettings.config file?

    <client>
        <endpoint address="http://MyWCFReference">
            <identity>
                <dns value="MyWCFReference"/>
            </identity>
        </endpoint>
    </client>

I was unable to find anything here or on the web that addressed this.  Thanks.
LVL 3
StormjackAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

StormjackAuthor Commented:
I just tried the above and the following error message gets returned when the code tries to create a new instance of the WFC (i.e. Using client As New MyWCF.ProductsClient):
Unrecognized attribute 'file'. Note that attribute names are case-sensitive.

It just seems that there should be some way to do this.  Thanks for your help.
0
SriVaddadiCommented:
You can add all the 3 endpoints to the config file as the address would be different for different servers.
0
happelCommented:
This link pretty much describes how to externalize System.ServiceModel contents.
Not the section itself, which remains in the app.config, but its contents (bindings etc).

http://stackoverflow.com/questions/858225/configsource-doesnt-work-in-system-servicemodel-or-its-subsections

If you really want to get rid of all WCF related settings in your configfile you need to create a custom
wcf channel factory (client side) which would read the neccesary settings from a source you choose (file, DB, etc) and create a WCF service channel for you.
Same principle goes for server-side but (a custom factory) but depends on how you host the service (IIS, selfhost)
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
StormjackAuthor Commented:
Thanks for the link Happel.  I'll give it a shot on Monday.  I wasn't able to work on this today.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
ASP.NET

From novice to tech pro — start learning today.