Question

I have an enterprise application consisting of an ASP.NET web app and a Windows Service. This has a number of "pluggable" connectors into other systems which use WCF (as a client and/or as a server). The pluggable connectors must be loaded into both the web app and the service during the startup process.

If I use the standard WCF configuration mechanism, I need to merge the WCF configuration for all the connectors together and then put it into both the web.config and the service.exe.config.

Ideally I'd like to have the WCF configuration for each connector as part of that connector's own configuration file, so as each connector is loaded at startup the WCF configuration for that connector is performed. This seems a much more modular/OO approach because all the configuration for one connector is grouped together in one place and separate from other configuration

I realise I could probably do this by using completely programmatic configuration but what I really want to do is be able to configure WCF at run-time by passing in a config section as text or DOM tree.

Is there any way to achieve this? I'm currently using .Net 3.5 but also interested in 4.5 because we're moving to that shortly.

Thanks in advance

Was it helpful?

Solution

There is no option that I can see that will allow access to a basic ServiceHost to load a configuration config section from an external source.

And there is no way that I can see that you can update or replace the system configuration in runtime (plus it doesn't make sense to change a config in a web app).

Your best option is to build a class that represents your different configuration options e.g. which binding and which security and so on. you can then save that class to an xml file using a serialization process. When a connector loads you grab the associated xml and deserialize it and build the service Host / Client Channel using pure code, should be fairly easy.

See Custom Service Host.

And for the client side just use a ChannelFactory.

Worst option is to use the OutOfTheBox element classes from System.ServiceModel.dll and implement half the WCF library on your own.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top