Multiple WCF services within single host returning root appsettings and not local

Multiple WCF services within single host returning root appsettings and not local

Old forum URL: forums.lhotka.net/forums/t/5347.aspx


Annesh posted on Friday, September 05, 2008

I have a 2 WCF services contained within a WCF WebApplication project hosted in Visual Studio Development server.

Folder structure looks like:

WCFHost <Root Folder>

ModuleA <Folder1>

      1) ModuleA_Service.svc + .cs

      2) IModuleA_Service.cs

   3) web.config <moduleA config which has ServiceModel settings and overridden appSettings>

ModuleB <Folder2>

      1) ModuleB_Service.svc + .cs

      2) IModuleB_Service.cs

   3) web.config <moduleB config which has ServiceModel settings and overridden appSettings>

1) web.config <root config>

 

Root web.config

--------------------------

<appSettings>

<add key="ClientName" value="ROOT"/>

</appSettings>

 

ModuleA config

--------------------

<appSettings>

<add key="ClientName" value="Module A"/>

</appSettings>

 

ModuleB config

------------------------

<appSettings>

<add key="ClientName" value="Module B"/>

</appSettings>
 


The services for both ModuleA and ModuleB simply returns the config value (note this is just a sample application, just illustrating the problem)

public string GetSetting()

{

return System.Configuration.ConfigurationManager.AppSettings["ClientName"];

}

The problem is that the service(which does work fine) returns the appsetting found in the root "clientName='root' " rather than the appsetting stored under its sibling web.config file which should read "clientName='Module A' ". Note the serviceModel settings are on the config files next to the .svc files. So it is using the right config file for the service setup but using the incorrect appsetting.

RockfordLhotka replied on Friday, September 05, 2008

The config file management is handled by ASP.NET. You'll need to research how ASP.NET handles the appSettings block in cases like this (I don't know the answer).

Copyright (c) Marimer LLC