A WCF webservice and the Application Settings horror
I have written a WCF service that I am hosting in IIS7 as a webservice. I 开发者_如何学Chave 8 application scope settings that I have defined in the WCF service library project in the app.config. I want to make these settings available to the network admins so that they can be changed as necessary without me having to open the solution, change the setting, recompile, re-deploy.
Using the app.config, that is case, because aparently the app.config is somehow incorporated into the built dll which is referenced by the webservice project.
So, I am trying to put these settings in the web.config. I have seen many sites that say simply to add the settings thusly:
<appSettings>
<add key="LDAPServerAddress" value="LDAP:/192.168.1.96/" />
<add key="ClientsOU" value="OU=Clients/" />
<add key="UsersOU" value="OU=Users" />
</appSettings>
which, upon running the service I am informed that User-Scoped settings are not allowed. I knew that, and that is why I attempted to create Application-Scoped settings (reference the above XML tag <appSettings>
).
I'm using what you have shown above.
Make sure <appSettings>
isn't contained in some other node other than the <configuration>
node in your web.config.
I read out the values like this:
var userName = ConfigurationManager.AppSettings["USER_NAME"];
Check the location of your appSettings node and compare how you're reading values with how I am above.
If that still doesn't work, I suggest eliminating everything else and creating a stupidly simple service with just one app setting. Set it up as you've shown above and see if the really simple service works as expected.
If so, you've got a problem elsewhere. If not, share the code for the simple service and we'll figure out what's going on.
精彩评论