I have a WPF application using Prism.
The application loads several modules.
Each module connects to one or more WCF Service.
The connection details are in the ‘app.config’ file of the Module library.
My question is – how do I make the ‘Shell’ project know about the endpoint configurations that are spread across different ‘app.config’ files in different assemblies.
Each client in different ‘Module’ that tries to connect – throws an exception that the ‘endpoint’ information could not be found…
UPDATE:
An alternative potential solution is to create the WCF clients in their own AppDomains.
See here for some ideas:
WCF ChannelFactory configuration outside of App.config?
Looking for a practical approach to sandboxing .NET plugins
I guess the question is how to get this working with Prism…the trick might be to have a custom IModuleManager (Prism V4), IModuleLoader (V1) or Catalog to deal with loading your WCF client modules, or perhaps have a wrapper module that in turn loads your WCF clients.
http://blog.thomaslebrun.net/2011/11/prism-load-modules-in-specific-order-even-for-modules-loaded-on-demand/#.UBpGtU1mSHU
https://prism.svn.codeplex.com/svn/V1/spikes/AGCompositeApplicationLibrary/AGComposite/Modularity/ModuleLoader.cs (this is from Prism V1…just for reference).
My first attempt at doing something similar to what you are doing was to hack the AppDomain configuration by doing this in my DLL module.
I can’t remember exactly, but I think I had to NOT define any ServiceModel configuration at all in my main application app.config (otherwise there would be a conflict in trying to replace it)…could be wrong on that…might have been the opposite, or might have been not have any app.config at all ! :o/. It was brittle for some reason….which I can’t remember off the top of my head.
I also tried getting access to the ServiceModel configuration from the ConfigurationManager at runtime and trying to modify that by code…but it would have none of it.
Anyhow, I don’t think the above will help you as you will be loading multiple modules, so need to load multiple configs.
So anyhow after trying the above I switched to a less brittle method by using a combination of:
from
and
CustomClientChannelFactory<T>from
http://svn.assembla.com/svn/pak/BuhServices/trunk/ExternalConfiguredChannel/CustomClientChannelFactory.cs
http://weblogs.asp.net/cibrax/archive/2007/10/19/loading-the-wcf-configuration-from-different-files-on-the-client-side.aspx
I put in some necessary fixes to get the ChannelFactory to work, and I modified it so I could choose if I wanted to override with my own configuration file, and also to support override of the address.
I used this constructor within the ExceptionHandlingProxyBase to create the factory:
You can disregard the ExceptionHandlingProxyBase part of this solution…that is just sugar that re-establishes the channel whenever the channel faults, so that you don’t have to worry about the state of your proxy.
If you still don’t want to use a ChannelFactory, then you could try hacking the ServiceModel configuration in your AppDomain. I tried that, but it seemed to be hard to modify
Here is the ChannelFactory code with the fixes in (stupidly renamed to CustomClientChannel).