IContractBehaviorAttribute.TargetContract Propriedade

Definição

Obtém o tipo do contrato ao qual o comportamento de contrato é aplicável.Gets the type of the contract to which the contract behavior is applicable.

public:
 property Type ^ TargetContract { Type ^ get(); };
public Type TargetContract { get; }
member this.TargetContract : Type
Public ReadOnly Property TargetContract As Type

Valor da propriedade

Type

O contrato ao qual o comportamento do contrato é aplicável.The contract to which the contract behavior is applicable.

Exemplos

O exemplo de código a seguir pressupõe uma System.ServiceModel.Dispatcher.IInstanceProvider implementação personalizada chamada ObjectProviderBehavior que fornece um comportamento "singleton"; ela sempre retorna a mesma instância de serviço e não a recicla.The following code example assumes a custom System.ServiceModel.Dispatcher.IInstanceProvider implementation called ObjectProviderBehavior that provides a "singleton" behavior; it always returns the same service instance and does not recycle it.

Para inserir a personalização do provedor de instância, o exemplo mostra como implementar um atributo personalizado ( SingletonBehaviorAttribute ) que implementa System.ServiceModel.Description.IContractBehavior para inserir o provedor de instância de serviço personalizado.To insert the instance provider customization, the example shows how to implement a custom attribute (SingletonBehaviorAttribute) that implements System.ServiceModel.Description.IContractBehavior to insert the custom service instance provider. Ele também implementa IContractBehaviorAttribute , que associa seu aplicativo ao ISampleService contrato.It also implements IContractBehaviorAttribute, which binds its application to the ISampleService contract.

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

Comentários

Implemente a TargetContract propriedade para especificar o contrato ao qual o comportamento do contrato é aplicado quando o atributo de implementação System.ServiceModel.Description.IContractBehavior é aplicado a uma classe de serviço.Implement the TargetContract property to specify the contract to which the contract behavior is applied when the implementing System.ServiceModel.Description.IContractBehavior attribute is applied to a service class.

Aplica-se a