IOperationBehavior Interface


The .NET API Reference documentation has a new home. Visit the .NET API Browser on to see the new experience.

Implements methods that can be used to extend run-time behavior for an operation in either a service or client application.

Namespace:   System.ServiceModel.Description
Assembly:  System.ServiceModel (in System.ServiceModel.dll)

public interface IOperationBehavior

System_CAPS_pubmethodAddBindingParameters(OperationDescription, BindingParameterCollection)

Implement to pass data at runtime to bindings to support custom behavior.

System_CAPS_pubmethodApplyClientBehavior(OperationDescription, ClientOperation)

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

System_CAPS_pubmethodApplyDispatchBehavior(OperationDescription, DispatchOperation)

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


Implement to confirm that the operation meets some intended criteria.

Implement the IOperationBehavior interface to modify, examine, or extend some aspect of operation-wide execution at the application level for either client or service applications.

  • Use the AddBindingParameters method to pass custom data at runtime to enable bindings to support custom behavior.

  • Use the ApplyClientBehavior method to modify, examine, or insert extensions to a client dispatcher in a client application.

  • Use the ApplyDispatchBehavior method to modify, examine, or insert extensions to operation-wide execution in a service application.

  • Use the Validate method to confirm that a OperationDescription meets specific requirements. This can be used to ensure that an operation has a certain configuration setting enabled, supports a particular feature and other requirements.

IOperationBehavior objects can make use of any of these methods, but often only one is important; in such cases, the unused methods can return, performing no action.


All of the IOperationBehavior methods pass an OperationDescription object as a parameter. This parameter is for examination only; if you modify the OperationDescription object the execution behavior is undefined.

IOperationBehavior objects are typically used to access the various properties of the System.ServiceModel.Dispatcher.DispatchOperation object in a service application and the System.ServiceModel.Dispatcher.ClientOperation object in a client application.

Typically, the developer first reviews the extensibility points to determine which customization option suits the application scenario and then implements the customization at the appropriate scope. For example, System.ServiceModel.Description.IServiceBehavior objects can insert customizations for all messages in an entire service and System.ServiceModel.Description.IContractBehavior objects can insert customizations for all messages across a specific contract, and so on. For a description of the various properties and customizations available, see Extending ServiceHost and the Service Model Layer.

Once a customization has been decided upon (and the customization interface implemented if necessary) and the IOperationBehavior is the appropriate scope of customization, the customization must be inserted into the Windows Communication Foundation (WCF) runtime by implementing IOperationBehavior and adding the operation behavior to the runtime.

There are two ways to add the IOperationBehavior to the runtime:

  • Programmatically add the custom operation behavior to the OperationDescription.Behaviors property prior to the opening of the service host (in a service application) or the channel factory (in a client application).

  • Add the behavior using a custom attribute.

To perform the service customization task for which it is intended, the IOperationBehavior object must be added to the OperationDescription.Behaviors property prior to the construction of the service runtime, which occurs when ICommunicationObject.Open method is called on System.ServiceModel.ServiceHost. To perform a client customization task, the IOperationBehavior object must be added to the OperationDescription.Behaviors property before calling the ChannelFactory<TChannel>.CreateChannel method or the ICommunicationObject.Open method on ChannelFactory<TChannel>.

Although the operation behavior is designed for easy access to the runtime at the scope of an individual operation, you can access the runtime at a larger scope by accessing the parent runtime object.

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;

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; }

Universal Windows Platform
Available since 8
.NET Framework
Available since 3.0
Portable Class Library
Supported in: portable .NET platforms
Available since 4.0
Return to top