This documentation is archived and is not being maintained.

ServiceDescription.Behaviors Property

Gets the behaviors associated with the service.

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

public KeyedByTypeCollection<IServiceBehavior> Behaviors { get; }

Property Value

Type: System.Collections.Generic.KeyedByTypeCollection<IServiceBehavior>
The KeyedByTypeCollection<TItem> of type IServiceBehavior that contains the behaviors associated with the service.

Use this method when adding custom behaviors to extend ServiceHost. Programmatically, you must Add(T) the custom service behavior to the Behaviors prior to when you call the Open method on the ServiceHost object.

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

If you want access to the IEndpointBehavior associated with an endpoint instead, you can obtain the endpoints for the service using the Endpoints property. Then retrieve the ServiceEndpoint from the collection with the Find method that employs the relevant search criteria, and call the Behaviors property to obtain the collection of the IEndpointBehavior objects.

//// Iterate through the list of behaviors in the ServiceDescription 
//ServiceDescription svcDesc = serviceHost.Description; 
//KeyedByTypeCollection<IServiceBehavior> sbCol = svcDesc.Behaviors; 
//foreach (IServiceBehavior behavior in sbCol) 
//    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