ServiceEndpoint.Behaviors Proprietà

Definizione

Ottiene i comportamenti per l'endpoint del servizio.

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

Valore della proprietà

KeyedByTypeCollection<IEndpointBehavior>

La classe KeyedByTypeCollection<TItem> di tipo IEndpointBehavior che contiene i comportamenti specificati per l'endpoint del servizio.

Esempio

Nel codice seguente viene illustrato come aggiungere un comportamento dell'endpoint personalizzato, quindi accedere a tale comportamento.

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

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

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

Console.WriteLine("List all behaviors:");
foreach (IEndpointBehavior behavior in endpoint.Behaviors)
{
    Console.WriteLine("Behavior: {0}", behavior.ToString());
}
Dim baseAddress As New Uri("http://localhost:8001/Simple")
Dim serviceHost As New ServiceHost(GetType(CalculatorService), baseAddress)

Dim endpoint As ServiceEndpoint = serviceHost.AddServiceEndpoint(GetType(ICalculator), New WSHttpBinding(), "CalculatorServiceObject")

endpoint.Behaviors.Add(New MyEndpointBehavior())

Console.WriteLine("List all behaviors:")
For Each behavior As IEndpointBehavior In endpoint.Behaviors
    Console.WriteLine("Behavior: {0}", CType(behavior, Object).ToString())
Next behavior

Commenti

Il tipo di comportamento accessibile dalla gerarchia della descrizione viene definito per l'ambito al livello specifico. Dalla classe ServiceEndpoint è accessibile l'interfaccia IEndpointBehavior .

Se si desidera accedere all'oggetto IContractBehavior associato a un endpoint, è possibile ottenere il contatto per l'endpoint utilizzando la proprietà Contract. Chiamare quindi la proprietà Behaviors per ottenere la classe KeyedByTypeCollection<TItem> degli oggetti IContractBehavior associati all'endpoint.

Si applica a