Behaviors
By and large, the service instance mode is strictly a service-side implementation detail
that should not manifest itself on the client side in any way. To support that and a few
other local service-side aspects, WCF defines the notion of behaviors.
A behavior is a local attribute of a service that does not affect its communication
patterns. Clients should be unaware of behaviors, and behaviors do not manifest themselves
in the service's binding or published metadata. WCF defines two types of service-side
behaviors, governed by two corresponding attributes. The ServiceBehaviorAttribute is used to configure service
behaviors; that is, behaviors that affect all endpoints (all contracts and
operations) of the service. The ServiceBehavior attribute
is applied directly on the service implementation class. You have already seen two behaviors
in the previous chapters: Chapter 1 used the service metadata
behavior to instruct the host to publish the service's metadata, and Chapter 3 used the service behavior to ignore the data object extension.
No client could ever tell simply by examining the communication and the exchanged messages
if the service is ignoring the data object extension or who was publishing its
metadata.
The OperationBehaviorAttribute is used to configure
operation behaviors; that is, behaviors that affect only the
implementation of a particular operation. The OperationBehavior attribute can be applied only on a method that implements a contract operation, never ...