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<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

注解

可从说明层次结构访问的行为类型限定在特定级别。 从 ServiceEndpoint 可以访问 IEndpointBehavior

如果您要访问与终结点关联的 IContractBehavior,则可以通过使用 Contract 属性来获取该终结点的协定。 然后,调用 Behaviors 属性可以获取与该终结点关联的 KeyedByTypeCollection<TItem> 对象的 IContractBehavior

适用于