IParameterInspector IParameterInspector IParameterInspector IParameterInspector Interface

Definição

Define o contrato implementado pelo inspetores de parâmetro personalizado que permite inspecionar ou modificar as informações antes e após as chamadas no cliente ou no serviço.Defines the contract implemented by custom parameter inspectors that enables inspection or modification of information prior to and subsequent to calls on either the client or the service.

public interface class IParameterInspector
public interface IParameterInspector
type IParameterInspector = interface
Public Interface IParameterInspector

Exemplos

O exemplo de código a seguir mostra uma implementação IParameterInspector que:The following code example shows an IParameterInspector implementation that:

  • Grava o nome da operação e o valor de retorno no console depois que uma resposta foi desserializada pelo serviço ou uma solicitação foi serializada por um cliente.Writes the operation name and return value to the console after a response has been deserialized by the service or a request has been serialized by a client.

  • Grava o nome da operação no console após a desserialização de uma resposta no cliente ou após a serialização de uma resposta no serviço.Writes the operation name to the console after deserializing a response on the client or after a response has been serialized on the service.

#region IParameterInspector Members
public void AfterCall(string operationName, object[] outputs, object returnValue, object correlationState)
{
  Console.WriteLine(
    "IParameterInspector.AfterCall called for {0} with return value {1}.", 
    operationName, 
    returnValue.ToString()
  );
}

public object BeforeCall(string operationName, object[] inputs)
{
  Console.WriteLine("IParameterInspector.BeforeCall called for {0}.", operationName);
  return null;
}
#Region "IParameterInspector Members"
    Public Sub AfterCall(ByVal operationName As String, ByVal outputs() As Object, ByVal returnValue As Object, _
                         ByVal correlationState As Object) Implements IParameterInspector.AfterCall
        Console.WriteLine("IParameterInspector.AfterCall called for {0} with return value {1}.", _
                          operationName, returnValue.ToString())
    End Sub

    Public Function BeforeCall(ByVal operationName As String, ByVal inputs() As Object) As Object Implements _
    IParameterInspector.BeforeCall
        Console.WriteLine("IParameterInspector.BeforeCall called for {0}.", operationName)
        Return Nothing
    End Function

O exemplo de código a seguir mostra como usar System.ServiceModel.Description.IOperationBehavior, System.ServiceModel.Description.IEndpointBehavior ou System.ServiceModel.Description.IServiceBehavior para inserir objetos IParameterInspector.The following code example shows how to use either System.ServiceModel.Description.IOperationBehavior, System.ServiceModel.Description.IEndpointBehavior or System.ServiceModel.Description.IServiceBehavior to insert IParameterInspector objects.

using System;
using System.Collections.Generic;
using System.ServiceModel;
using System.ServiceModel.Channels;
using System.ServiceModel.Configuration;
using System.ServiceModel.Description;
using System.ServiceModel.Dispatcher;
using System.Text;

namespace Microsoft.WCF.Documentation
{
  public class InspectorInserter : BehaviorExtensionElement, IServiceBehavior, IEndpointBehavior, IOperationBehavior
  {
    #region IServiceBehavior Members
    public void AddBindingParameters(
      ServiceDescription serviceDescription, 
      ServiceHostBase serviceHostBase, 
      System.Collections.ObjectModel.Collection<ServiceEndpoint> endpoints, 
      BindingParameterCollection bindingParameters
    )
    { return; }

    public void ApplyDispatchBehavior(ServiceDescription serviceDescription, ServiceHostBase serviceHostBase)
    {
      foreach (ChannelDispatcher chDisp in serviceHostBase.ChannelDispatchers)
      {
        foreach (EndpointDispatcher epDisp in chDisp.Endpoints)
        {
          epDisp.DispatchRuntime.MessageInspectors.Add(new Inspector());
          foreach (DispatchOperation op in epDisp.DispatchRuntime.Operations)
            op.ParameterInspectors.Add(new Inspector());
        }
      }
    }

    public void Validate(ServiceDescription serviceDescription, ServiceHostBase serviceHostBase){ return; }

    #endregion
    #region IEndpointBehavior Members
    public void AddBindingParameters(
      ServiceEndpoint endpoint, BindingParameterCollection bindingParameters
    ) { return; }

    public void ApplyClientBehavior(ServiceEndpoint endpoint, ClientRuntime clientRuntime)
    {
      clientRuntime.MessageInspectors.Add(new Inspector());
      foreach (ClientOperation op in clientRuntime.Operations)
        op.ParameterInspectors.Add(new Inspector());
    }

    public void ApplyDispatchBehavior(ServiceEndpoint endpoint, EndpointDispatcher endpointDispatcher)
    {
      endpointDispatcher.DispatchRuntime.MessageInspectors.Add(new Inspector());
      foreach (DispatchOperation op in endpointDispatcher.DispatchRuntime.Operations)
        op.ParameterInspectors.Add(new Inspector());
    }

    public void Validate(ServiceEndpoint endpoint){ return; }
    #endregion
    #region IOperationBehavior Members
    public void AddBindingParameters(
      OperationDescription operationDescription, BindingParameterCollection bindingParameters
    )
    { return; }

    public void ApplyClientBehavior(OperationDescription operationDescription, ClientOperation clientOperation)
    {
      clientOperation.ParameterInspectors.Add(new Inspector());
    }

    public void ApplyDispatchBehavior(OperationDescription operationDescription, DispatchOperation dispatchOperation)
    {
      dispatchOperation.ParameterInspectors.Add(new Inspector());
    }

    public void Validate(OperationDescription operationDescription){ return; }

    #endregion

    public override Type BehaviorType
    {
      get { return typeof(InspectorInserter); }
    }

    protected override object CreateBehavior()
    { return new InspectorInserter(); }
  }
}
Imports System.ServiceModel
Imports System.ServiceModel.Channels
Imports System.ServiceModel.Configuration
Imports System.ServiceModel.Description
Imports System.ServiceModel.Dispatcher
Imports System.Text

Namespace Microsoft.WCF.Documentation
  Public Class InspectorInserter
      Inherits BehaviorExtensionElement
      Implements IServiceBehavior, IEndpointBehavior, IOperationBehavior
    #Region "IServiceBehavior Members"
        Public Sub AddBindingParameters(ByVal serviceDescription As ServiceDescription, _
                       ByVal serviceHostBase As ServiceHostBase, ByVal endpoints As  _
                       System.Collections.ObjectModel.Collection(Of ServiceEndpoint), _
                       ByVal bindingParameters As BindingParameterCollection) Implements IServiceBehavior.AddBindingParameters
            Return
        End Sub

        Public Sub ApplyDispatchBehavior(ByVal serviceDescription As ServiceDescription, _
                                         ByVal serviceHostBase As ServiceHostBase) Implements _
                                         IServiceBehavior.ApplyDispatchBehavior
            For Each chDisp As ChannelDispatcher In serviceHostBase.ChannelDispatchers
                For Each epDisp As EndpointDispatcher In chDisp.Endpoints
                    epDisp.DispatchRuntime.MessageInspectors.Add(New Inspector())
                    For Each op As DispatchOperation In epDisp.DispatchRuntime.Operations
                        op.ParameterInspectors.Add(New Inspector())
                    Next op
                Next epDisp
            Next chDisp
        End Sub

        Public Sub Validate(ByVal serviceDescription As ServiceDescription, ByVal serviceHostBase As ServiceHostBase) _
        Implements IServiceBehavior.Validate
            Return
        End Sub

    #End Region
    #Region "IEndpointBehavior Members"
        Public Sub AddBindingParameters(ByVal endpoint As ServiceEndpoint, ByVal bindingParameters _
                                        As BindingParameterCollection) Implements IEndpointBehavior.AddBindingParameters
            Return
        End Sub

        Public Sub ApplyClientBehavior(ByVal endpoint As ServiceEndpoint, ByVal clientRuntime As ClientRuntime) _
        Implements IEndpointBehavior.ApplyClientBehavior
            clientRuntime.MessageInspectors.Add(New Inspector())
            For Each op As ClientOperation In clientRuntime.Operations
                op.ParameterInspectors.Add(New Inspector())
            Next op
        End Sub

        Public Sub ApplyDispatchBehavior(ByVal endpoint As ServiceEndpoint, ByVal endpointDispatcher As  _
                                         EndpointDispatcher) Implements IEndpointBehavior.ApplyDispatchBehavior
            endpointDispatcher.DispatchRuntime.MessageInspectors.Add(New Inspector())
            For Each op As DispatchOperation In endpointDispatcher.DispatchRuntime.Operations
                op.ParameterInspectors.Add(New Inspector())
            Next op
        End Sub

    Public Sub Validate(ByVal endpoint As ServiceEndpoint) Implements IEndpointBehavior.Validate
        Return
    End Sub
    #End Region
    #Region "IOperationBehavior Members"
        Public Sub AddBindingParameters(ByVal operationDescription As OperationDescription, _
                                        ByVal bindingParameters As BindingParameterCollection) Implements _
                                        IOperationBehavior.AddBindingParameters
            Return
        End Sub

        Public Sub ApplyClientBehavior(ByVal operationDescription As OperationDescription, ByVal _
                                       clientOperation As ClientOperation) Implements IOperationBehavior.ApplyClientBehavior
            clientOperation.ParameterInspectors.Add(New Inspector())
        End Sub

        Public Sub ApplyDispatchBehavior(ByVal operationDescription As OperationDescription, ByVal dispatchOperation As  _
                                         DispatchOperation) Implements IOperationBehavior.ApplyDispatchBehavior
            dispatchOperation.ParameterInspectors.Add(New Inspector())
        End Sub

    Public Sub Validate(ByVal operationDescription As OperationDescription) Implements IOperationBehavior.Validate
        Return
    End Sub

    #End Region

    Public Overrides ReadOnly Property BehaviorType() As Type
      Get
          Return GetType(InspectorInserter)
      End Get
    End Property

    Protected Overrides Function CreateBehavior() As Object
        Return New InspectorInserter()
    End Function
  End Class
End Namespace

Comentários

Implemente a interface IParameterInspector para criar um inspetor de parâmetro personalizado que possa exibir e modificar o conteúdo de uma chamada antes da chamada e depois da chamada em aplicativos cliente ou de serviço.Implement the IParameterInspector interface to create a custom parameter inspector that can view and modify the contents of a call both before the call and after the call in either client or service applications.

Em chamadas de saída de um cliente, o Inspetor é invocado antes que o conteúdo da solicitação seja serializado e enviado ao serviço.On outbound calls from a client, the inspector is invoked before the request contents are serialized and sent to the service. O Inspetor também é chamado depois que a resposta é desserializada, mas antes que os valores de retorno sejam expedidos para o método de proxy.The inspector is also called after the response has been deserialized but before the return values have been dispatched to the proxy method.

Em chamadas de entrada para um serviço, o Inspetor é invocado depois que os parâmetros são desserializados, mas antes de serem expedidos para a operação de serviço.On inbound calls to a service, the inspector is invoked after parameters are deserialized but before they are dispatched to the service operation.

Use as propriedades ClientOperation.ParameterInspectors ou DispatchOperation.ParameterInspectors para adicionar uma implementação de IParameterInspector à coleção de inspetores para uma operação específica.Use the ClientOperation.ParameterInspectors or the DispatchOperation.ParameterInspectors properties to add an IParameterInspector implementation to the inspectors collection for a particular operation.

Observação Os desenvolvedores e administradores devem garantir que a interação com outras implementações de @no__t 1 seja compreendida.Note Developers and administrators must ensure that the interaction with other IParameterInspector implementations is understood.

Métodos

AfterCall(String, Object[], Object, Object) AfterCall(String, Object[], Object, Object) AfterCall(String, Object[], Object, Object) AfterCall(String, Object[], Object, Object)

Chamado depois que as chamadas do cliente são retornadas e antes que as respostas do serviço são enviadas.Called after client calls are returned and before service responses are sent.

BeforeCall(String, Object[]) BeforeCall(String, Object[]) BeforeCall(String, Object[]) BeforeCall(String, Object[])

Chamado antes de chamadas do cliente serem enviadas e depois de respostas de serviço serem retornadas.Called before client calls are sent and after service responses are returned.

Aplica-se a