I know this is old, but there has never been an answer to it, so I thought I would take a picture. If I understand what you need, you can do this using the special ServiceHostFactory service.
Good post on this here .
You configured your custom ServiceHostFactory like this:
<%@ ServiceHost Language="C#" Debug="true" Service="Ionic.Samples.Webservices.Sep20.CustomConfigService" Factory="Ionic.ServiceModel.ServiceHostFactory"%>
Then in your ServiceHostFactory you can override a method called ApplyConfiguration. Typically, for WCF applications hosted in IIS, WCF automatically looks for configuration in web.config. In this example, we override this behavior to first look for a configuration file named after the WCF service description.
protected override void ApplyConfiguration() {
You can replace this with "anything" - for example, searching for a configuration in a database table.
A few more methods complete the puzzle.
private string _physicalPath = null; private string physicalPath { get { if (_physicalPath == null) { // if hosted in IIS _physicalPath = System.Web.Hosting.HostingEnvironment.ApplicationPhysicalPath; if (String.IsNullOrEmpty(_physicalPath)) { // for hosting outside of IIS _physicalPath= System.IO.Directory.GetCurrentDirectory(); } } return _physicalPath; } } private void LoadConfigFromCustomLocation(string configFilename) { var filemap = new System.Configuration.ExeConfigurationFileMap(); filemap.ExeConfigFilename = configFilename; System.Configuration.Configuration config = System.Configuration.ConfigurationManager.OpenMappedExeConfiguration (filemap, System.Configuration.ConfigurationUserLevel.None); var serviceModel = System.ServiceModel.Configuration.ServiceModelSectionGroup.GetSectionGroup(config); bool loaded= false; foreach (System.ServiceModel.Configuration.ServiceElement se in serviceModel.Services.Services) { if(!loaded) if (se.Name == this.Description.ConfigurationName) { base.LoadConfigurationSection(se); loaded= true; } } if (!loaded) throw new ArgumentException("ServiceElement doesn't exist"); }
Cheeso
source share