IServiceBehavior::ApplyDispatchBehavior Method (ServiceDescription^, ServiceHostBase^)


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

Provides the ability to change run-time property values or insert custom extension objects such as error handlers, message or parameter interceptors, security extensions, and other custom extension objects.

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

void ApplyDispatchBehavior(
	ServiceDescription^ serviceDescription,
	ServiceHostBase^ serviceHostBase


Type: System.ServiceModel.Description::ServiceDescription^

The service description.

Type: System.ServiceModel::ServiceHostBase^

The host that is currently being built.

Implement the ApplyDispatchBehavior method to inspect or modify the ServiceHostBase object that is being constructed in order to support some custom execution scenario.


All of the IServiceBehavior methods pass System.ServiceModel.Description::ServiceDescription and System.ServiceModel::ServiceHostBase objects as a parameters. The ServiceDescription parameter is for examination and insertion of customizations only; if you otherwise modify these objects the execution behavior is undefined.

The following code example shows the use of a service behavior specified in a configuration file to insert a custom error handler in a service application. In this example, the error handler catches all exceptions and converts them into a custom GreetingFault SOAP fault that is then returned to the client.

The following IServiceBehavior implementation adds no binding parameter objects, adds the custom System.ServiceModel.Dispatcher::IErrorHandler object to each ChannelDispatcher::ErrorHandlers property, and validates that each operation of the service to which the service behavior is applied and has a System.ServiceModel::FaultContractAttribute of type GreetingFault.

No code example is currently available or this language may not be supported.

In this example, the behavior class also implements System.ServiceModel.Configuration::BehaviorExtensionElement, which enables the service behavior to be inserted by using it in an application configuration file, as the following code example demonstrates.

.NET Framework
Available since 3.0
Return to top