I have a self-hosted WCF (as a Windows service), it has a web.config file.
Inside one of the functions, I have this code (which doesn’t seem to work):
Shell(System.Configuration.ConfigurationManager.AppSettings("ExStream_CMD_File_Path"), AppWinStyle.NormalFocus)
The web.config looks like this:
<configuration>
<configSections>
<sectionGroup name="system.web.extensions" type="System.Web.Configuration.SystemWebExtensionsSectionGroup, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35">
<sectionGroup name="scripting" type="System.Web.Configuration.ScriptingSectionGroup, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35">
<section name="scriptResourceHandler" type="System.Web.Configuration.ScriptingScriptResourceHandlerSection, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" allowDefinition="MachineToApplication"/>
<sectionGroup name="webServices" type="System.Web.Configuration.ScriptingWebServicesSectionGroup, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35">
<section name="jsonSerialization" type="System.Web.Configuration.ScriptingJsonSerializationSection, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" allowDefinition="Everywhere"/>
<section name="profileService" type="System.Web.Configuration.ScriptingProfileServiceSection, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" allowDefinition="MachineToApplication"/>
<section name="authenticationService" type="System.Web.Configuration.ScriptingAuthenticationServiceSection, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" allowDefinition="MachineToApplication"/>
<section name="roleService" type="System.Web.Configuration.ScriptingRoleServiceSection, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" allowDefinition="MachineToApplication"/>
</sectionGroup>
</sectionGroup>
</sectionGroup>
</configSections>
<appSettings>
<add key="ExStream_CMD_File_Path" value="C:\HelloWorld.cmd"/>
</appSettings>
<connectionStrings/>
<system.web>
...
For one reason or another, it just won’t go. So I tried to reference my application settings in a console app & its app.config. Tried to read it with ConfigurationManager.AppSettings, but errored “Not a member of Configuration”, then tried ConfigurationSettings.AppSettings — but errored “Method is obsolete, use ConfigurationManager”. Redundant!
How can I just reference a simple string in my config file in a WCF?
Thanks,
Jason
I don’t think web.config has the correct configuration filename for the windows service, self-hosted service (it’d be for a webhosted service in IIS). Try checking the value of
AppDomain.CurrentDomain.SetupInformation.ConfigurationFileon your hosting code, that will tell you what the config file name should be. And callingSystem.Configuration.ConfigurationManager.AppSettings("ExStream_CMD_File_Path")should work just fine.