共用方式為


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

備註

可從描述階層存取的行為的型別會限定在特定層級的範圍內。 ServiceEndpoint 可從 IEndpointBehavior 存取。

如果您想要存取與端點相關聯的 IContractBehavior,可以使用 Contract 屬性取得端點的合約。 然後呼叫 Behaviors 屬性,以取得與端點有關聯的 KeyedByTypeCollection<TItem> 物件的 IContractBehavior

適用於