ServiceEndpoint.Behaviors 属性
定义
获取服务终结点的行为。Gets the behaviors for the service endpoint.
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。The KeyedByTypeCollection<TItem> of type IEndpointBehavior that contains the behaviors specified for the service endpoint.
示例
下面的代码演示了如何添加自定义终结点行为,以及接着如何访问该行为。The following code demonstrates how to add a custom endpoint behavior and then access that behavior.
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
注解
可从说明层次结构访问的行为类型限定在特定级别。The type of behavior that is accessible from the description hierarchy is scoped to the specific level. 从 ServiceEndpoint 可以访问 IEndpointBehavior。From the ServiceEndpoint the IEndpointBehavior is accessible.
如果您要访问与终结点关联的 IContractBehavior,则可以通过使用 Contract 属性来获取该终结点的协定。If you want access to the IContractBehavior associated with an endpoint, you can obtain the contact for the endpoint using the Contract property. 然后,调用 Behaviors 属性可以获取与该终结点关联的 KeyedByTypeCollection<TItem> 对象的 IContractBehavior。Then call the Behaviors property to obtain the KeyedByTypeCollection<TItem> of the IContractBehavior objects associated with the endpoint.