ServiceEndpoint.Behaviors 屬性

定義

取得服務端點的行為。

C#
public System.Collections.Generic.KeyedByTypeCollection<System.ServiceModel.Description.IEndpointBehavior> Behaviors { get; }

屬性值

包含針對服務端點指定的行為的型別 KeyedByTypeCollection<TItem>IEndpointBehavior

範例

下列程式碼會示範如何加入自訂端點行為,然後存取該行為。

C#
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());
}

備註

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

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

適用於

產品 版本
.NET Framework 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1