Provides a mechanism to modify or insert custom extensions across an entire service, including the ServiceHostBase.
Assembly: System.ServiceModel (in System.ServiceModel.dll)
|AddBindingParameters(ServiceDescription, ServiceHostBase, Collection<ServiceEndpoint>, BindingParameterCollection)|
Provides the ability to pass custom data to binding elements to support the contract implementation.
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.
Provides the ability to inspect the service host and the service description to confirm that the service can run successfully.
Implementto modify, examine, or extend some aspect of service-wide execution at the application level:
Use the ApplyDispatchBehavior method 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.
Use the Validate method to examine the description before Windows Communication Foundation (WCF) constructs the executing service to confirm that it can execute properly.
Use the AddBindingParameters method to pass to a binding element the custom information for the service so that it can support the service correctly.
objects can make use of any of these methods, but often only one is important; in such cases the unused methods can return without a value.
All of the System.ServiceModel.Description.ServiceDescription and System.ServiceModel.ServiceHostBase objects as a parameters. The ServiceDescription parameter is for examination only; if you modify these objects the execution behavior is undefined.methods pass
To perform the customization task for which it is intended, the Behaviors property prior to the construction of the service runtime. There are three ways to do this:object must be added to the
Create a custom attribute that implements ServiceHost object is constructed, WCF uses reflection to discover the attributes on the service type. If any attributes implement , they are added to the behaviors collection on ServiceDescription.and use it to mark service classes that are to be modified. When a
Extend the System.ServiceModel.Configuration.BehaviorExtensionElement class to support the specification of the behavior in an application or machine configuration file. See the Example section for more information.
Examples of service behaviors in WCF include the ServiceBehaviorAttribute attribute, the System.ServiceModel.Description.ServiceThrottlingBehavior, the System.ServiceModel.Description.ServiceDebugBehavior and the System.ServiceModel.Description.ServiceMetadataBehavior behavior.
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 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.implementation adds no binding parameter objects, adds the custom
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.
Available since 3.0