Service and Operation behaviors in WCF

Behaviors in WCF are used to say how it’s going to behave at the service level, endpoint level or operation level. ServiceBehaviorAttribute  is used to apply behaviors at the service level. To apply behaviors at operation level use OperationBehaviorAttribute.

ServiceBehaviorAttribute: This attribute can be applied only to service implementations. It has properties that are useful in enabling a specified feature for the service.

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

  1. Any:  matches on any address of an incoming message
  2. Exact: exact match on the address of an incoming message
  3. Prefix: prefix match on the address of an incoming message
  • AutomaticSessionShutdown: allows to automatically close the session when the channel is closed and the service has finished processing any remaining messages.(true/false)
  • ConcurrencyMode: controls the internal threading model, enabling support for reentrant or multithreaded services.

  1. Single: Service instance is single-threaded and does not accept reentrant calls (other messages must wait)
  2. Reentrant:Service instance is single-threaded accepts reentrant calls. the reentrant service accepts calls when you call another service (make the object state consistent before callouts and make operation-local data is valid after callouts.)
  3. Multiple: service is a multi-threaded. (Synchronization need to be maintained).
  • ConfigurationName: used to declare a name for use in the name attribute of the <service> element in the config file.
  • IgnoreExtensionDataObject: enables the run time to ignore extra serialization informatin that is not required to process the message.(true/false).
  • IncludeExceptionDetailInFaults: enables the unhandled exceptions in a service to return in SOAP faults. Used for debugging purposes.(true/false)
  • InstanceContextMode: specifies whether and when services and their service objects are to be recycled during an exchange with a client.

  1. persession: new instance object is created for each session.
  2. percall: new instance object is created prior to and recycled subsequent to each call.(defaults for no session)
  3. Single: only one instance object is used for all incoming calls.
  • MaxItemsInObjectGraph: used to limit on the number of items in an object graph that are serialized.(number)
  • Name and Namespace: controls the name and namespace for WSDL.
  • ReleaseServiceInstanceOnTransactionComplete: specifies whether the service object is recycled when a transaction completes.(true/false)
  • TransactionAutoCompleteSessionClose: specifies whether outstanding transactions are completed when the session closes.(true/false)
  • TransactionIsolationLevel: specifies the transaction isolation level that the contract supports.(isolationlevel of)

  1. Serializable: volatile data can be read but not modified, and no new dat can be added during the transaction.
  2. RepeatableRead:volatile data can be read but not modified during the transaction. New data can be added during the transaction.
  3. ReadCommitted: volatile data cannot be read during the transaction, but can be modified.
  4. ReadUncommitted: volatile data can be read and modified during the transaction.
  5. snapshot:volatile data can be read. Before a transaction modified data, it verified if another transaction has changed the data after it was intitially read. If the data has been updated, an error is raised. This allows a transaction to get to the previously committed value of the data.
  6. chaos: pending changes from more highly isolated transactions cannot be overwritten.
  7. upspecified:a different isolation level than the one specified is being used, but the level cannot be determined. An exception is thrown if this value is set.
  • TransactionTimeout: specifies the time period within which a transaction must complete or it aborts.
  • UseSynchronizationContext: indicates whether to synchronize inbound method calls with the user interface thread automatically.
  • ValidateMustUnderstand: informs the system whether it should confirm that SOAP headers marked as MustUnderstand have, in fact, been understood.

 

Leave a Reply

Your email address will not be published. Required fields are marked *