Tag Archives: Windows Communication Foundation

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.

 

Windows Communication Foundation

Since WCF has been introduced in .Net 3.0, it’s keep growing and the features available are also improving. Lets see how WCF works.

Actually there are many reasons to communicate one application to another or utilize resources available in the market. There are different connection scenarios for this. Webservices is one such where one application exposes a service which can consumed by clients which are able access that. There can be one-way, request-reply or duplex types of communications.
Earlier Microsoft shipped different tools for each type of communications. So it’s really a correct solution. So they introduced WCF which is able to perform all the major communication types available in the market.
The process of WCF is simple:
Typically, for any client to consume the service what it needs is
1. Where to find the service?
2. How to connect the service?
3. And What are the operations available from the service?
With the WCF, they have provided different bindings(System Provided) to define the connectivity part

BindingConfiguration ElementDescription
BasicHTTPBinding<basicHttpBinding>This binding is more suitable for communication with basic WS-Basic profile webservices. Similar to ASP.Net Webservices (ASMX). This uses HTTP as transport protocol and MTOM(xml) as default message encoding. Supports Transport, Message and Mixed security modes. Will not support Sessions and Transactions. Supports buffered streaming.
WSHTTPBinding<wsHttpBinding>Provides secure and interoperable communication (WS*), suitable for non duplex connections. Uses SOAP protocol, and text as default encoding. Supports security (Transport, Mixed, Message modes), by default at message mode. Supports Sessions (Reliable, Security) by default none.
WSDualHttpBinding<wsDualHttpBinding>Provides secure, interoperable, reliable and duplex communication contract with text encoding by default. Supports Security at message level by default and only security mode available. Supports sessions(Reliable, Security) with reliablesession as default.
WSFederationHttpBinding<wsFederationHttpBinding>This binding is basically used federation communication. supports security(Message, Mixed, none) at Message level by default. Supports sessions (Reliable, Security). Transactions are allowed.
NetHttpBinding<netHttpBinding>This binding is basically designed for consuming HTTP or websocket services and uses binary encoding by default. Websockets are only supported on Windows 8. NetHttpBinding will check for request-reply or duplex contract and change its behavior accordingly. It will use HTTP for request-reply and websockets for duplex.
NetHttpsBinding<netHttpsBinding>A secure netHttpBinding.
NetTcpBinding<netTcpBinding>This binding replaces the earlier .net remoting. This secure way of communicating between two WCF capable services.
NetNamedPipeBinding<netNamedPipeBinding>This binding generates a run-time communication stack by default, which uses transport security, named pipes for message delivery and a binary message encoding. This is appropriate for on machine WCF communications. It also supports transactions.
NetMsmqBinding<netMsmqBinding>This binding provides support for queuing by using Message Queuing (MSMQ) as a transport and enables support for loosely-coupled applications, failure isolation, load leveling and disconnected operations.
NetPeerTcpBinding<netPeerTcpBinding>This binding provides a secure connection for multiple machine communication. provides support for the creation of peer networking applications that use a TCP-level peer-to-peer mesh infrastructure. Each PeerNode instance can host multiple peer channels defined with this binding type.
MsmqIntegrationBinding<msmqIntegrationBinding>This binding is suitable for cross-machine communication between a WCF application and existing MSMQ applications.
WebHttpBinding<webHttpBinding>WCF allows to expose WCF web services through HTTP requests that use "plan old XML" (POX) style messaging instead of SOAP-based messaging. For clients to communicate with a service using HTTP requests, an endpoint of the service must be configured with the WebHttpBinding that has the WebHttpBehavior attached to it. The WCF also requires that the individual service operations are annotated with WebGet or WebInvoke attributes.