Apply the ServiceBehaviorAttribute attribute to a service implementation to specify service-wide execution behavior. (To specify execution behavior at the method level, use the OperationBehaviorAttribute attribute.) This attribute can be applied only to service implementations. For working examples, see the Service Behaviors Samples.

ServiceBehaviorAttribute properties are a Windows Communication Foundation (WCF) programming model feature that enables common features that developers otherwise have to implement. For more information about these and other behaviors, see Specifying Service Run-Time Behavior. For more information about the underlying runtime properties that some of the following properties set, see Extending ServiceHost and the Service Model Layer.

The AddressFilterMode property specifies the type of filter that the dispatcher system uses to locate the endpoint that handles requests.

The AutomaticSessionShutdown property automatically closes the session when the channel is closed and the service has finished processing any remaining messages.

The ConcurrencyMode property controls the internal threading model, enabling support for reentrant or multithreaded services.

The ConfigurationName property is used to declare a name for use in the name attribute of the <service> element in a configuration file.

The IgnoreExtensionDataObject property enables the run time to ignore extra serialization information that is not required to process the message.

The IncludeExceptionDetailInFaults property specifies whether unhandled exceptions in a service are returned as SOAP faults. This is for debugging purposes only.

The InstanceContextMode property specifies whether and when services and their service objects are to be recycled during an exchange with a client.

The MaxItemsInObjectGraph property to limit on the number of items in an object graph that are serialized.

The Name and Namespace properties control the name and namespace for the WSDL expression of the service element.

The following code example demonstrates the ServiceBehaviorAttribute properties. The BehaviorService class uses the ServiceBehaviorAttribute attribute to indicate that:

The service object is recycled when the transaction completes.

There is one service object for each session.

The service is single-threaded and does not support reentrant calls.

Furthermore, at the operation level, the OperationBehaviorAttribute values indicate that the TxWork method automatically enlists in flowed transactions or creates a new transaction to do the work, and that the transaction is committed automatically if an unhandled exception does not occur.

The underlying binding must support flowed transactions for the following code example to execute properly. To support flowed transactions using the WSHttpBinding, for example, set the TransactionFlow property to true in code or in an application configuration file. The following code example shows the configuration file for the preceding sample.