• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 866
  • Last Modified:

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.
0
Stormjack
Asked:
Stormjack
  • 2
1 Solution
 
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
 
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: CompTIA Cloud+

The CompTIA Cloud+ Basic training course will teach you about cloud concepts and models, data storage, networking, and network infrastructure.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now