问题
I'm building a component that is an extension for another software product. It's loaded as a dll into that product, and therefore I don't have control over the main exe's app.config file. My component uses WCF and I'd like to be able to configure it using a .config file instead of programmatically within the code. Is there a way to tell WCF to get all the binding etc settings from a specific config file?
回答1:
The .NET config file mechanism is scoped by AppDomain, so in principle you could achieve this by creating a separate AppDomain to host your WCF stuff. It's quite a lot of work, though, as you would have to code the necessary cross-domain communication to expose your extension functionality to the host process.
回答2:
Ultimately @marc_s's answer was the one I went with: no. Instead we store configuration options with other system settings and then apply them programmatically to the binding etc settings at runtime.
来源:https://stackoverflow.com/questions/4928807/how-to-tell-wcf-client-to-read-settings-out-of-different-config-file