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
[ServiceContract(Namespace="http://Microsoft.Samples.ConfigHierarchicalModel")]
public interface IDesc
{
[OperationContract]
List<string> ListEndpoints();
[OperationContract]
List<string> ListServiceBehaviors();
[OperationContract]
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
Using Visual Studio 2010, open the ConfigHierarchicalModel.sln file.
The client project is not already set up as the start-up project, follow these steps.
In Solution Explorer, right-click the solution and then select Properties.
In Common Properties, select Startup Project, and then click Single startup project.
From the Single startup project drop-down, select Client.
Click OK to close the dialog.
To build the sample, press CTRL+SHIFT+B.
To run the client, press Ctrl+F5.
Note: |
---|
If these steps do not work, then make sure that your environment has been properly set up, using the following steps.
|
Note: |
---|
The samples may already be installed on your computer. Check for the following (default) directory before continuing.
<InstallDrive>:\WF_WCF_Samples
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.
<InstallDrive>:\WF_WCF_Samples\WCF\Basic\Services\ConfigHierarchicalModel
|