ServiceDescription.Behaviors Özellik

Tanım

Hizmetle ilişkili davranışları alır.

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)

Özellik Değeri

Hizmetle KeyedByTypeCollection<TItem> ilişkili davranışları içeren türü IServiceBehavior .

Örnekler

// 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()

Açıklamalar

genişletmek ServiceHostiçin özel davranışlar eklerken bu yöntemi kullanın. Program aracılığıyla, nesnesinde yöntemini ServiceHost çağırdığınızda öncekine Open özel hizmet davranışını Behaviors belirtmeniz gerekirAdd(T).

Açıklama hiyerarşisinden erişilebilen davranış türü, belirli bir düzey kapsamındadır. ServiceDescriptionIServiceBehavior'den erişilebilir.

Bunun yerine bir uç noktayla ilişkilendirilmiş öğesine IEndpointBehavior erişmek istiyorsanız, özelliğini kullanarak Endpoints hizmetin uç noktalarını alabilirsiniz. Ardından ilgili arama ölçütlerini kullanan yöntemiyle Find koleksiyonundan öğesini alın ServiceEndpoint ve nesnesinin Behaviors koleksiyonunu almak için özelliğini çağırınIEndpointBehavior.

Şunlara uygulanır