IOperationBehavior.ApplyClientBehavior(OperationDescription, ClientOperation) Method


Implements a modification or extension of the client across an operation.

 void ApplyClientBehavior(System::ServiceModel::Description::OperationDescription ^ operationDescription, System::ServiceModel::Dispatcher::ClientOperation ^ clientOperation);
public void ApplyClientBehavior (System.ServiceModel.Description.OperationDescription operationDescription, System.ServiceModel.Dispatcher.ClientOperation clientOperation);
abstract member ApplyClientBehavior : System.ServiceModel.Description.OperationDescription * System.ServiceModel.Dispatcher.ClientOperation -> unit
Public Sub ApplyClientBehavior (operationDescription As OperationDescription, clientOperation As ClientOperation)



The operation being examined. Use for examination only. If the operation description is modified, the results are undefined.


The run-time object that exposes customization properties for the operation described by operationDescription.


The following code example shows an implementation of System.ServiceModel.Dispatcher.IParameterInspector that writes to the console when the inspector is invoked on an operation. This customization can only be attached to the System.ServiceModel.Dispatcher.DispatchOperation or System.ServiceModel.Dispatcher.ClientOperation and is therefore usually inserted by an operation behavior.

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

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 _
        Console.WriteLine("IParameterInspector.BeforeCall called for {0}.", operationName)
        Return Nothing
    End Function

The following code example shows how the operation behavior attaches the parameter inspector to the runtime.

#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; }
#Region "IOperationBehavior Members"
    Public Sub AddBindingParameters(ByVal operationDescription As OperationDescription, _
                                    ByVal bindingParameters As BindingParameterCollection) Implements _
    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
End Sub


Implement the ApplyClientBehavior method to view, modify, or add a custom extension to the client runtime across all messages used with a specific operation. For details about what customizations you can do with a client run-time object, see ClientRuntime and ClientOperation.

It is recommended that the ApplyClientBehavior method throw a NotImplementedException if the behavior is only intended for use in a service application.

Applies to