ENTERPRISE

Programming WCF Services : Instance Management - Behaviors

1/31/2015 8:20:34 PM

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 the service or the client that does not affect its communication patterns. Clients should be unaware of service behaviors, and behaviors do not manifest themselves in the service’s binding or published metadata.

WCF defines two types of declarative 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. Apply the ServiceBehavior attribute directly on the service implementation class.

Use the OperationBehaviorAttribute 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 on the operation definition in the contract itself. 

The ServiceBehavior attribute is used to configure the service instance mode. As shown in Example 1, the attribute defines the InstanceContextMode property of the enum type InstanceContextMode. The value of the InstanceContextMode enum controls which instance mode is used for the service.

Example 1. ServiceBehaviorAttribute used to configure the instance context mode

public enum InstanceContextMode{   PerCall,   PerSession,   Single}[AttributeUsage(AttributeTargets.Class)]public sealed class ServiceBehaviorAttribute : Attribute,...{   public InstanceContextMode InstanceContextMode   {get;set;}   //More members}

The enum is correctly called InstanceContextMode rather than InstanceMode because it actually controls the instantiation mode of the context hosting the instance, rather than that of the instance itself. By default, however, the instance and its context are treated as a single unit, so the enum does control the life of the instance as well. 

Other  
  •  SAP Planning : Best Practices Approach to Staffing the SAP TSO
  •  Creating Interactive Windows Services : Services and Polling - Using Configuration Files
  •  Creating Interactive Windows Services : Services and Polling - Updating Tutorials.ThreadFunc
  •  Windows System Programming : Exception Handling - Vectored Exception Handling
  •  Windows System Programming : Exception Handling - Example: A Console Control Handler
  •  Windows System Programming : Exception Handling - Console Control Handlers
  •  Microsoft Enterprise Library : Relieving Cryptography Complexity - Diving in with an Example (part 2) - Obtaining and Comparing Hash Values
  •  Microsoft Enterprise Library : Relieving Cryptography Complexity - Diving in with an Example (part 1) - Encrypting and Decrypting Data Using A Symmetric Provider
  •  Microsoft Enterprise Library : Relieving Cryptography Complexity - How Do I Use the Cryptography Block?
  •  Microsoft Enterprise Library : Relieving Cryptography Complexity - What Does the Cryptography Block Do?
  •  
    Top 10
    Review : Sigma 24mm f/1.4 DG HSM Art
    Review : Canon EF11-24mm f/4L USM
    Review : Creative Sound Blaster Roar 2
    Review : Philips Fidelio M2L
    Review : Alienware 17 - Dell's Alienware laptops
    Review Smartwatch : Wellograph
    Review : Xiaomi Redmi 2
    Extending LINQ to Objects : Writing a Single Element Operator (part 2) - Building the RandomElement Operator
    Extending LINQ to Objects : Writing a Single Element Operator (part 1) - Building Our Own Last Operator
    3 Tips for Maintaining Your Cell Phone Battery (part 2) - Discharge Smart, Use Smart
    REVIEW
    - First look: Apple Watch

    - 3 Tips for Maintaining Your Cell Phone Battery (part 1)

    - 3 Tips for Maintaining Your Cell Phone Battery (part 2)
    VIDEO TUTORIAL
    - How to create your first Swimlane Diagram or Cross-Functional Flowchart Diagram by using Microsoft Visio 2010 (Part 1)

    - How to create your first Swimlane Diagram or Cross-Functional Flowchart Diagram by using Microsoft Visio 2010 (Part 2)

    - How to create your first Swimlane Diagram or Cross-Functional Flowchart Diagram by using Microsoft Visio 2010 (Part 3)
    Popular Tags
    Video Tutorail Microsoft Access Microsoft Excel Microsoft OneNote Microsoft PowerPoint Microsoft Project Microsoft Visio Microsoft Word Active Directory Exchange Server Sharepoint Sql Server Windows Server 2008 Windows Server 2012 Windows 7 Windows 8 Adobe Flash Professional Dreamweaver Adobe Illustrator Adobe Photoshop CorelDRAW X5 CorelDraw 10 windows Phone 7 windows Phone 8 Iphone
    Visit movie_stars's profile on Pinterest.