Store/manipulate WCF config settings in SQL Server?

Nov 11 2009 9:47 AM
Hey all.

I have a problem with config settings for WCF that I was hoping I could get some advice on.

Basically, normally you would store all your config sections for WCF in the ServiceModel etc. Now storing all of these in a config file is something we do not want to do at my work place. Basically we have a lot of applications running on different machines, and we would like to be able to store/manipulate these easily, and also take away the possibility of users/support staff from manually changing a config file.

One possible solution I have been trying to think about, is to store the full ServiceModel hierarchy as an XML string in SQL Server. But I am unsure how I could take this XML string and use it for the bindings for a WCF service. i..e how to attach these settings. I do not want to store all the settings individually in the database and then hard code each setting in code to pick these up as that would take away all the flexibility of the config file.

Can I read a column from the database as an XML string and attach the full XML string as the config to be used by the service?

I could possibly create a temp file from the xml string (not ideal but possible) and then use code like the following:

Configuration appConfig = ConfigurationManager.OpenExeConfiguration("test.xml");>
ServiceModelSectionGroup serviceModel = ServiceModelSectionGroup.GetSectionGroup(appConfig);>
BindingsSection bindings = serviceModel.Bindings;

but then when I create the end point for the service, I cant seem to get to a specific binding from that bindings object,

this.LoadingService.AddServiceEndpoint(typeof(IMessageLoader), ServiceBinding, ServiceUri);

Here, I would want the "ServiceBinding" reference changed to have the actual binding from the" bindings" object.

Thanks, Paul.