ServiceDescription.Behaviors ServiceDescription.Behaviors ServiceDescription.Behaviors ServiceDescription.Behaviors Property

定義

サービスに関連付けられている動作を取得します。Gets the behaviors associated with the service.

public:
 property System::Collections::Generic::KeyedByTypeCollection<System::ServiceModel::Description::IServiceBehavior ^> ^ Behaviors { System::Collections::Generic::KeyedByTypeCollection<System::ServiceModel::Description::IServiceBehavior ^> ^ get(); };
public System.Collections.Generic.KeyedByTypeCollection<System.ServiceModel.Description.IServiceBehavior> Behaviors { get; }
member this.Behaviors : System.Collections.Generic.KeyedByTypeCollection<System.ServiceModel.Description.IServiceBehavior>
Public ReadOnly Property Behaviors As KeyedByTypeCollection(Of IServiceBehavior)

プロパティ値

サービスに関連付けられている動作を含む KeyedByTypeCollection<TItem> 型の IServiceBehaviorThe KeyedByTypeCollection<TItem> of type IServiceBehavior that contains the behaviors associated with the service.

// Iterate through the list of behaviors in the ServiceDescription
ServiceDescription svcDesc = serviceHost.Description;
KeyedByTypeCollection<IServiceBehavior> sbCol = svcDesc.Behaviors;
foreach (IServiceBehavior behavior in sbCol)
{
    Console.WriteLine("Behavior: {0}", behavior.ToString());
}
Uri baseAddress = new Uri("http://localhost:8001/Simple");
ServiceHost serviceHost = new ServiceHost(typeof(CalculatorService), baseAddress);

serviceHost.AddServiceEndpoint(
    typeof(ICalculator),
    new WSHttpBinding(),
    "CalculatorServiceObject");

// Enable Mex
ServiceMetadataBehavior smb = new ServiceMetadataBehavior();
smb.HttpGetEnabled = true;
serviceHost.Description.Behaviors.Add(smb);

ServiceDescription sd = serviceHost.Description;
sd.Behaviors.Add(new MyCustomBehavior());

serviceHost.Open();
' Iterate through the list of behaviors in the ServiceDescription
Dim svcDesc As ServiceDescription = serviceHost.Description
Dim sbCol As KeyedByTypeCollection(Of IServiceBehavior) = svcDesc.Behaviors
For Each behavior As IServiceBehavior In sbCol
    Console.WriteLine("Behavior: {0}", CType(behavior, Object).ToString())
Next behavior
Dim baseAddress As New Uri("http://localhost:8001/Simple")
Dim serviceHost As New ServiceHost(GetType(CalculatorService), baseAddress)

serviceHost.AddServiceEndpoint(GetType(ICalculator), New WSHttpBinding(), "CalculatorServiceObject")

' Enable Mex
Dim smb As New ServiceMetadataBehavior()
smb.HttpGetEnabled = True
serviceHost.Description.Behaviors.Add(smb)

Dim sd As ServiceDescription = serviceHost.Description
sd.Behaviors.Add(New MyCustomBehavior())

serviceHost.Open()

注釈

カスタム動作を追加するときにこのメソッドを使用して、ServiceHost を拡張します。Use this method when adding custom behaviors to extend ServiceHost. プログラムにより、Add(T) オブジェクトで Behaviors メソッドを呼び出すより前に、Open を実行して、カスタム サービス動作を ServiceHost に追加する必要があります。Programmatically, you must Add(T) the custom service behavior to the Behaviors prior to when you call the Open method on the ServiceHost object.

説明階層からアクセスできる動作の型は、特定のレベルに限定されます。The type of behavior that is accessible from the description hierarchy is scoped to the specific level. ServiceDescription から、IServiceBehavior にアクセスできます。From the ServiceDescription the IServiceBehavior is accessible.

代わりに、エンドポイントに関連付けられた IEndpointBehavior にアクセスする場合は、Endpoints プロパティを使用してサービスのエンドポイントを取得します。If you want access to the IEndpointBehavior associated with an endpoint instead, you can obtain the endpoints for the service using the Endpoints property. 次に、 ServiceEndpoint関連する検索Behaviors条件をFind使用するメソッドを使用してコレクションからを取得し、プロパティを呼び出してIEndpointBehaviorオブジェクトのコレクションを取得します。Then retrieve the ServiceEndpoint from the collection with the Find method that employs the relevant search criteria, and call the Behaviors property to obtain the collection of the IEndpointBehavior objects.

適用対象