ServiceDescription.Behaviors Propriété

Définition

Obtient les comportements associés au service.

public:
 property System::Collections::Generic::KeyedByTypeCollection<System::ServiceModel::Description::IServiceBehavior ^> ^ Behaviors { System::Collections::Generic::KeyedByTypeCollection<System::ServiceModel::Description::IServiceBehavior ^> ^ get(); };
public System.Collections.Generic.KeyedByTypeCollection<System.ServiceModel.Description.IServiceBehavior> Behaviors { get; }
member this.Behaviors : System.Collections.Generic.KeyedByTypeCollection<System.ServiceModel.Description.IServiceBehavior>
Public ReadOnly Property Behaviors As KeyedByTypeCollection(Of IServiceBehavior)

Valeur de propriété

KeyedByTypeCollection<IServiceBehavior>

KeyedByTypeCollection<TItem> de type IServiceBehavior qui contient les comportements associés au service.

Exemples

// 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());
}
Uri baseAddress = new Uri("http://localhost:8001/Simple");
ServiceHost serviceHost = new ServiceHost(typeof(CalculatorService), baseAddress);

serviceHost.AddServiceEndpoint(
    typeof(ICalculator),
    new WSHttpBinding(),
    "CalculatorServiceObject");

// Enable Mex
ServiceMetadataBehavior smb = new ServiceMetadataBehavior();
smb.HttpGetEnabled = true;
serviceHost.Description.Behaviors.Add(smb);

ServiceDescription sd = serviceHost.Description;
sd.Behaviors.Add(new MyCustomBehavior());

serviceHost.Open();
' Iterate through the list of behaviors in the ServiceDescription
Dim svcDesc As ServiceDescription = serviceHost.Description
Dim sbCol As KeyedByTypeCollection(Of IServiceBehavior) = svcDesc.Behaviors
For Each behavior As IServiceBehavior In sbCol
    Console.WriteLine("Behavior: {0}", CType(behavior, Object).ToString())
Next behavior
Dim baseAddress As New Uri("http://localhost:8001/Simple")
Dim serviceHost As New ServiceHost(GetType(CalculatorService), baseAddress)

serviceHost.AddServiceEndpoint(GetType(ICalculator), New WSHttpBinding(), "CalculatorServiceObject")

' Enable Mex
Dim smb As New ServiceMetadataBehavior()
smb.HttpGetEnabled = True
serviceHost.Description.Behaviors.Add(smb)

Dim sd As ServiceDescription = serviceHost.Description
sd.Behaviors.Add(New MyCustomBehavior())

serviceHost.Open()

Remarques

Utilisez cette méthode lors de l'ajout de comportements personnalisés pour étendre ServiceHost. Par programme, vous devez Add(T) le comportement de service personnalisé aux Behaviors avant d'appeler la méthode Open sur l'objet ServiceHost.

Le type de comportement qui est accessible à partir de la hiérarchie de description est inclus à la portée du niveau spécifique. À partir de la ServiceDescription, le IServiceBehavior est accessible.

Si vous souhaitez accéder au IEndpointBehavior plutôt associée à un point de terminaison, vous pouvez obtenir les points de terminaison pour le service à l'aide de la propriété Endpoints. Récupérez ensuite la ServiceEndpoint collection avec la Find méthode qui utilise les critères de recherche pertinents et appelez la Behaviors propriété pour obtenir la collection des IEndpointBehavior objets.

S’applique à