This documentation is archived and is not being maintained.

ServiceEndpoint.Behaviors Property

Gets the behaviors for the service endpoint.

Namespace:  System.ServiceModel.Description
Assembly:  System.ServiceModel (in System.ServiceModel.dll)

public KeyedByTypeCollection<IEndpointBehavior> Behaviors { get; }

Property Value

Type: System.Collections.Generic.KeyedByTypeCollection<IEndpointBehavior>
The KeyedByTypeCollection<TItem> of type IEndpointBehavior that contains the behaviors specified for the service endpoint.

The type of behavior that is accessible from the description hierarchy is scoped to the specific level. From the ServiceEndpoint the IEndpointBehavior is accessible.

If you want access to the IContractBehavior associated with an endpoint, you can obtain the contact for the endpoint using the Contract property. Then call the Behaviors property to obtain the KeyedByTypeCollection<TItem> of the IContractBehavior objects associated with the endpoint.

The following code demonstrates how to add a custom endpoint behavior and then access that behavior.

Uri baseAddress = new Uri("http://localhost:8001/Simple");
ServiceHost serviceHost = new ServiceHost(typeof(CalculatorService), baseAddress);

ServiceEndpoint endpoint = serviceHost.AddServiceEndpoint(
    new WSHttpBinding(),

endpoint.Behaviors.Add(new MyEndpointBehavior());

Console.WriteLine("List all behaviors:");
foreach (IEndpointBehavior behavior in endpoint.Behaviors)
    Console.WriteLine("Behavior: {0}", behavior.ToString());

Windows 7, Windows Vista, Windows XP SP2, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003

The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

.NET Framework

Supported in: 3.5, 3.0