web.config inheritance/merge/scoping of appSettings not working in IIS Hosted WCF/Workflow Service in sub-folder

StackOverflow https://stackoverflow.com/questions/8929641

Question

I am currently testing the following structure in IIS for my AppFabric Workflow Services and WCF Services:

/WebApp/ <-- IIS Application here
/WebApp/bin/ <-- binaries here
/WebApp/web.config <-- empty.
/WebApp/WorkflowApp/V1.0/web.config  <-- Settings are stored here
/WebApp/WorkflowApp/V1.0/MyWorkflow.xamlx
/WebApp/WorkflowApp/V1.0/Default.aspx <-- just for testing
/WebApp/WcfService/V1.0/web.config  <-- Settings are stored here
/WebApp/WcfService/V1.0/MyService.svc
/WebApp/WcfService/V1.0/Default.aspx <-- just for testing

My web.config contains the following section:

<appSettings>
  <add key="TestSetting" value="Test Setting Value" />
</appSettings>

From one of my code activities in my workflow service, and from inside my WCF service, I want to read an item from "appSettings" using the following code:

var config = ConfigurationManager.AppSettings["TestSetting"];

This always returns null. I also tried WebConfigurationManager.AppSettings["TestSetting"], but this also returns null. It seems that the web.config hierarchy is not working for appSettings.

Just for testing, I added a Default.aspx with the following contents to see if this appSetting is accessible from an ASP.NET web page, and it works!

<html>
    <body>
        <h2>
            TestWebApp
        </h2>
        <%= ConfigurationManager.AppSettings["TestSetting"] %>
    </body>
</html>

It seems that the web.config in the sub-folder is not processed at all. Why doesn't the configuration scoping not work for AppFabric workflow/WCF services? And what can I do to make it work?

If I place the workflow/WCF service in the root of my web applicaiton in IIS, the appSettings section is accessible as expected. It is only when I place my workflow service in a sub-directory, the configuration sections are not accessible.

Update:

I have modified the question to generalize it to WCF and Workflow services, because it affects both cases. The reason I'm trying this, is to reduce the number of IIS applications and application pools.

According to the Windows Server AppFabric Architecture Guide:

Similarly to the application pool planning, we recommend that you logically group multiple services into a web application where it makes sense. AppFabric is designed to handle hundreds of web applications. However, for optimum performance and manageability, the goal should be to keep the number of web applications as small as practically possible.

From this text, it leads me to believe that having multiple WCF/Workflow services in sub-folders of web apps should work.

Was it helpful?

Solution

I believe the problem is that your workflow is not running on the ASP.NET thread but on it's own thread in the thread pool. As a result it doesn't really care about ASP.NET scoping rules but use the standard AppDomain config file.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top