WCF Services—ServiceBehavior Attribute


Jump to: navigation, search
Visual C# Tutorials
.NET Framework Tutorials

WCF Services

© 2007 Chris Peiris, Dennis Mulder

ServiceBehavior Attribute

So far, we’ve focused specifically on the contract definition. We’ve intentionally avoided any discussion of how a service behaves. Generally, service behavior is an implementation-dependant aspect of a solution. In addition to using ServiceBehavior, you also have an ability to apply behavior at the operation level with the OperationBehavior attribute (covered in the next section).

The ServiceBehavior attribute is applicable only at the class (implementation) level. Although the ServiceContract attribute was applicable at both the interface (contract) and the class levels, it is this distinction that is important. Behaviors in WCF are not part of the contract; they are implementation-specific aspects.

The capability exists to control service-wide behavior elements such as the following:

Concurrency: Controls threading behavior for an object and whether it supports reentrant calls. Valid only if the Instancing property is not PerCall.
Instancing: Controls new object creation and control object lifetime. The default is PerCall, which causes a new object on each method call. Generally, in session-oriented services, providing either PerSession or Shareable may provide better performance, albeit at the cost of concurrency management.
Throttling: Managed through configuration, when concurrency allows for multiple calls, to limit the number of concurrent calls, connections, total instances, and pending operations.
Transaction: Controls transaction aspects such as autocompletion, isolation level, and object recycling.
Session management: Provides automatic session shutdown or overrides default behavior.
Thread behavior: Forces the service thread to have affinity to the UI thread; this is helpful if the underlying service host is a WinForms application and updates to controls on that form may happen in the service implementation.


Previous_Page_.gif Next_Page_.gif

Share this page
  • del.icio.us
  • Facebook
  • Google+
  • StumbleUpon