IContractBehaviorAttribute Interface

Definitie

Hiermee geeft u het contract op waarvoor een kenmerk waarmee de IContractBehavior interface wordt geïmplementeerd actief is.

public interface class IContractBehaviorAttribute
public interface IContractBehaviorAttribute
type IContractBehaviorAttribute = interface
Public Interface IContractBehaviorAttribute
Afgeleid

Voorbeelden

In het volgende codevoorbeeld wordt ervan uitgegaan dat een aangepaste System.ServiceModel.Dispatcher.IInstanceProvider implementatie ObjectProviderBehavior die een singleton-gedrag biedt. Het retourneert altijd hetzelfde service-exemplaar en recyclet deze niet.

Als u de aanpassing van de instantieprovider wilt invoegen, ziet u in het voorbeeld hoe u een aangepast kenmerk (SingletonBehaviorAttribute) implementeert om System.ServiceModel.Description.IContractBehavior de provider van het aangepaste service-exemplaar in te voegen. Het implementeert IContractBehaviorAttributeook , waarmee de toepassing ervan aan het ISampleService contract wordt gebonden.

public class SingletonBehaviorAttribute : Attribute, IContractBehaviorAttribute, IContractBehavior
{

  #region IContractBehaviorAttribute Members

  public Type TargetContract
  {
    get { return typeof(ISampleService); }
  }

  #endregion

  #region IContractBehavior Members

  public void AddBindingParameters(ContractDescription description, ServiceEndpoint endpoint, System.ServiceModel.Channels.BindingParameterCollection parameters)
  {
    return;
  }

  public void ApplyClientBehavior(ContractDescription description, ServiceEndpoint endpoint, ClientRuntime clientRuntime)
  {
    return;
  }

  public void ApplyDispatchBehavior(ContractDescription description, ServiceEndpoint endpoint, DispatchRuntime dispatch)
  {
    dispatch.InstanceProvider = new ObjectProviderBehavior("Custom ObjectProviderBehavior constructor.");
  }

  public void Validate(ContractDescription description, ServiceEndpoint endpoint)
  {
    return;
  }

  #endregion
}
Public Class SingletonBehaviorAttribute
    Inherits Attribute
    Implements IContractBehaviorAttribute, IContractBehavior

  #Region "IContractBehaviorAttribute Members"

  Public ReadOnly Property TargetContract() As Type Implements IContractBehaviorAttribute.TargetContract
    Get
        Return GetType(ISampleService)
    End Get
  End Property

  #End Region

  #Region "IContractBehavior Members"

  Public Sub AddBindingParameters(ByVal description As ContractDescription, ByVal endpoint As ServiceEndpoint, ByVal parameters As System.ServiceModel.Channels.BindingParameterCollection) Implements IContractBehavior.AddBindingParameters
    Return
  End Sub

  Public Sub ApplyClientBehavior(ByVal description As ContractDescription, ByVal endpoint As ServiceEndpoint, ByVal clientRuntime As ClientRuntime) Implements IContractBehavior.ApplyClientBehavior
    Return
  End Sub

  Public Sub ApplyDispatchBehavior(ByVal description As ContractDescription, ByVal endpoint As ServiceEndpoint, ByVal dispatch As DispatchRuntime) Implements IContractBehavior.ApplyDispatchBehavior
    dispatch.InstanceProvider = New ObjectProviderBehavior("Custom ObjectProviderBehavior constructor.")
  End Sub

  Public Sub Validate(ByVal description As ContractDescription, ByVal endpoint As ServiceEndpoint) Implements IContractBehavior.Validate
    Return
  End Sub

  #End Region
End Class

Opmerkingen

Implementeer de IContractBehaviorAttribute interface op een kenmerk dat ook een System.ServiceModel.Description.IContractBehavior object is om het gebruik van dat kenmerk contractgedrag voor een servicetype in te schakelen, maar de toepassing ervan te beperken tot het contract dat is opgegeven in de TargetContract eigenschap.

Er is geen vereiste om te implementeren IContractBehaviorAttribute op aangepaste contractgedragskenmerken en als het kenmerk wordt toegepast op een contractinterface of op een duplex callbackklasse, wordt de waarde van de TargetContract eigenschap genegeerd.

Zie System.ServiceModel.Description.IContractBehavior voor meer informatie.

Eigenschappen

Name Description
TargetContract

Hiermee haalt u het type contract op waarop het contractgedrag van toepassing is.

Van toepassing op