Configure WCF client at runtime from XML file RRS feed

  • Question

  • Hi

    Since we use a special config system in our application that also uses xml files which are parsed at runtime, i also want/need to to integrate WCF configuration in our main config system. So we have only one config file and system.

    Our system is somewhat cumbersome, so I want to reference an app.config-styled xml file into our config system like

    config. file "bla.accfg"

    <class ID="WcfClient1" ... >
             <Property Name="WcfConfigFile" Value="WcfClient1.config" />

    and the wcf config in "WcfClient1.config" is identical to the settings of app.config <sytem.serviceModel> section

    				<binding name="NetTcpBinding_IInstallationCommunciationService">
    					<security mode="None"></security>
                <endpoint address="net.tcp://localhost:9002/InstallationCommunciationService" binding="netTcpBinding" bindingConfiguration="NetTcpBinding_IInstallationCommunciationService" contract="IInstallationCommunciationService" name="NetTcpBinding_IInstallationCommunciationService">
                        <servicePrincipalName value="host/XXX-ZZZfutura"/>

    So when the app stzarts i read the "WcfConfigFile" property in my "WcfClient1" instance, find file "WcfClient1.config" then I want to conigure my WcfCleint accoridng to the setttings found in this file.

    How can I achieve it?
    I know there is are new APIs in .NET 4.5 like "ServiceHost.ApplyConfiguration" and "ConfigurationManager.OpenMappedExeConfiguration".
    Whcih is the right one?

    Regards, Chris

    Wednesday, January 21, 2015 4:06 PM

All replies

  • In short I want to know how I can configure a wcf client, that derives from ClientBase<T>,  at runtime to get the binding and endpoint from a config file (app.config format) so I can potentially change this file and switch the security or switch from NetTcp to Http or chnage the server's endpoint adress or such like.

    like Pseudo-code:

    MyClient client = new MyClient(Configuration.FromFile(....));

    Wednesday, January 21, 2015 5:36 PM
  • Yes, we can configure the config file in client side.

    Vote if help you

    Friday, January 23, 2015 12:30 PM