Reputation: 15807
We are using .NET Extensions in our WCF service and this means that on startup the Extension folder will be checked for dll files and if there is any, then these will be loaded as extensions.
The problem is that the extesions might have its own config file with endpoints but when running the extension from within the WCF service we will bee in the WCF service appdomain and this means that the WCF service web.config will be used to locate the endpoints.
Yes I could move the endpoints to the web.config but If I do this, then the extension would be more bound and this are not the thought of extensions I think.
I could probably also change the appdomain temporarly within the extension dll but is this really the right way to got?
Upvotes: 1
Views: 181
Reputation: 15807
The solution is to use the following code :
string path = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location);
ExeConfigurationFileMap fileMap = new ExeConfigurationFileMap() { ExeConfigFilename = path + @"\MyExtension.dll.config" };
//ExeConfigurationFileMap fileMap = new ExeConfigurationFileMap() { ExeConfigFilename = path + @"\unittesting.dll.config" };
Configuration configuration = ConfigurationManager.OpenMappedExeConfiguration(fileMap, ConfigurationUserLevel.None);
ConfigurationChannelFactory<MyExtension.MyExtentionManService.GetObjectResponderInterface> factory = new ConfigurationChannelFactory<GetObjectResponderInterface>("GetObjectResponderPort", configuration, null);
This is new in .NET 4.0.
Upvotes: 1