Поделиться через


ServiceEndpoint.Behaviors Свойство

Определение

Возвращает поведение конечной точки службы.

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)

Значение свойства

Тип KeyedByTypeCollection<TItem>IEndpointBehavior , содержащий поведение, указанное для конечной точки службы.

Примеры

В следующем коде показано, как добавить поведение пользовательской конечной точки и получить доступ к этому поведению.

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

Комментарии

Тип поведения, доступного из иерархии описания, ограничен определенным уровнем. Из нее ServiceEndpointIEndpointBehavior доступен.

Если вы хотите получить доступ к связанной IContractBehavior конечной точке, можно получить контакт для конечной точки с помощью Contract свойства. Затем вызовите Behaviors свойство, чтобы получить KeyedByTypeCollection<TItem>IContractBehavior объекты, связанные с конечной точкой.

Применяется к