This documentation is archived and is not being maintained.

Hierarchical Configuration Model

This sample demonstrates how to implement a hierarchy of configuration files for services. It also shows how bindings, service behaviors, and endpoint behaviors are inherited from higher levels in the hierarchy.

Sample details

One of the features developed for WCF in .NET Framework version 4 is the improvement in the hierarchical configuration model. An example of a hierarchical configuration model would be the one defined by Machine.config -> Rootweb.config -> Web.config. In .NET Framework 4, those bindings and behaviors that are defined in upper levels in the configuration hierarchy are added to your services with no explicit configuration. This sample shows how it is possible to simplify your service configuration by relying on configuration elements defined at the computer or the application level.

This sample consists of nine services, defined in three levels of hierarchy. Service1 is at the root. Service2 and Service3 inherit the default elements from Service1. Service4, Service5, Service6 and Service7 are defined at a third level of the hierarchy, inheriting the default elements from Service3. Finally Service10 and Service11 are at a fourth level of the hierarchy.

All the services implement the IDesc contract. The following is the definition of the IDesc interface that shows the methods exposed in this interface. The IDesc interface is defined in Service1.cs.

    // Define a service contract
    public interface IDesc
        List<string> ListEndpoints();
        List<string> ListServiceBehaviors();
        List<string> ListEndpointBehaviors();

The implementation of these methods by the services is straightforward. ListEndpoints iterates through all the service endpoints and returns a list of all the endpoints that the service has. ListServiceBehaviors iterates through all the behaviors added to the service and returns the list of all the service behaviors associated with the service. ListEndpointBehaviors behaves in a similar way to ListServiceBehaviors, but it returns the list of endpoint behaviors instead.

This implementation allows the client to know how many endpoints the service is exposing and which service behaviors and endpoint behaviors have been added to the service. The client that has been implemented as part of the sample adds a service reference to all the services in the solution and shows these elements for each one of the services.

To use this sample

To run the client

  1. Using Visual Studio 2010, open the ConfigHierarchicalModel.sln file.

  2. The client project is not already set up as the start-up project, follow these steps.

    1. In Solution Explorer, right-click the solution and then select Properties.

    2. In Common Properties, select Startup Project, and then click Single startup project.

    3. From the Single startup project drop-down, select Client.

    4. Click OK to close the dialog.

  3. To build the sample, press CTRL+SHIFT+B.

  4. To run the client, press Ctrl+F5.

If these steps do not work, then make sure that your environment has been properly set up, using the following steps.

  1. Ensure that you have performed the One-Time Setup Procedure for the Windows Communication Foundation Samples.

  2. To build the solution, follow the instructions in Building the Windows Communication Foundation Samples.

  3. To run the sample in a single or multiple computer configurations, follow the instructions in Running the Windows Communication Foundation Samples.

Ee663221.Important(en-us,VS.100).gif Note:
The samples may already be installed on your computer. Check for the following (default) directory before continuing.


If this directory does not exist, go to Windows Communication Foundation (WCF) and Windows Workflow Foundation (WF) Samples for .NET Framework 4 to download all Windows Communication Foundation (WCF) and WF samples. This sample is located in the following directory.


See Also