Pages

Monday 14 May 2012

WCF: A SOA based Service Framework


WCF stands for Windows Communication Foundation (Code Name: Indigo). Windows Communication Foundation (WCF) is a framework for building service-oriented applications. It is unified programming model provided in .Net Framework 3.0. WCF is meant for designing and deploying distributed applications under Service Oriented Architecture (SOA) implementation. WCF accomodates functionalities of its older communication technologies like:

1. Web Service (ASMX)
2. Web Service Enhancement (WSE)
3. Microsoft Message Queuing (MSMQ)
4. Component Object Model (COM+)
5. .Net Remoting

Components of WCF:

1. Service: A service is basically a class written in a .Net compliant language which contains some methods that are exposed through the WCF service. A service may have one or more endpoints – an endpoint is responsible for communication from the service to the client.

2. End Points: The End Points consists Address (Where), Contract (What) and Binding (How).

Address (Where): Indicates where a webservice could be found. Technically speaking, URL of the webservice.

Contract (What): Contract is an agreement between two or more parties. It defines the protocol how client should communicate with your service. Technically speaking, it describes parameters and return values for a web method in a web service.

Binding (How): Binding specifies what communication protocols are used to access the service, whether security mechanisms are to be used, and the like. WCF includes predefined bindings for most common communication protocols such as SOAP over HTTP, SOAP over TCP, and SOAP over Message Queues, etc. Interaction between WCF endpoint and client is done using a SOAP envelope. SOAP envelopes are in simple XML form that makes WCF platform independent.

The mnemonic "ABC" can be used to remember address / binding / Contract.

3. Hosting Environment: WCF can be hosted on IIS or on other environment (Self-hosting). There are two main advantages of using IIS over self-hosting:-

Automatic activation: IIS provides automatic activation that means the service is not necessary to be running in advance. When any message is received by the service it then launches and fulfills the request. But in case of self hosting the service should always be running.

Process recycling: If IIS finds any memory leaks etc in web service, IIS recycles the process.

Features of WCF:

Service Orientation: One consequence of using WS standards is that WCF enables you to create service oriented applications. Service-oriented architecture (SOA) is the reliance on Web services to send and receive data. The services have the general advantage of being loosely-coupled instead of hard-coded from one application to another. A loosely-coupled relationship implies that any client created on any platform can connect to any service as long as the essential contracts are met.

Interoperability: WCF implements modern industry standards for Web service interoperability.

Multiple Message Patterns: Messages are exchanged in one of several patterns. The most common pattern is the request/reply pattern, where one endpoint requests data from a second endpoint. The second endpoint replies. There are other patterns such as a one-way message in which a single endpoint sends a message without any expectation of a reply. A more complex pattern is the duplex exchange pattern where two endpoints establish a connection and send data back and forth, similar to an instant messaging program.

Service Metadata: WCF supports publishing service metadata using formats specified in industry standards such as WSDL, XML Schema and WS-Policy. This metadata can be used to automatically generate and configure clients for accessing WCF services. Metadata can be published over HTTP and HTTPS or using the Web Service Metadata Exchange standard.

Data Contracts: Because WCF is built using the .NET Framework, it also includes code-friendly methods of supplying the contracts you want to enforce. One of the universal types of contracts is the data contract. In essence, as you code your service using Visual C# or Visual Basic, the easiest way to handle data is by creating classes that represent a data entity with properties that belong to the data entity. WCF includes a comprehensive system for working with data in this easy manner. Once you have created the classes that represent data, your service automatically generates the metadata that allows clients to comply with the data types you have designed.

Security: Messages can be encrypted to protect privacy and you can require users to authenticate themselves before being allowed to receive messages. Security can be implemented using well-known standards such as SSL or WS-SecureConversation.

Multiple Transports and Encodings: Messages can be sent on any of several built-in transport protocols and encodings. The most common protocol and encoding is to send text encoded SOAP messages using is the HyperText Transfer Protocol (HTTP) for use on the World Wide Web. Alternatively, WCF allows you to send messages over TCP, named pipes, or MSMQ. These messages can be encoded as text or using an optimized binary format. Binary data can be sent efficiently using the MTOM standard. If none of the provided transports or encodings suit your needs you can create your own custom transport or encoding.

Reliable and Queued Messages: WCF supports reliable message exchange using reliable sessions implemented over WS-Reliable Messaging and using MSMQ.

Durable Messages: A durable message is one that is never lost due to a disruption in the communication. The messages in a durable message pattern are always saved to a database. If a disruption occurs, the database allows you to resume the message exchange when the connection is restored. You can also create a durable message using the Windows Workflow Foundation (WF).

Transactions: WCF also supports transactions using one of three transaction models: WS-AtomicTtransactions, the APIs in the System.Transactions namespace, and Microsoft Distributed Transaction Coordinator.

AJAX and REST Support: REST is an example of an evolving Web 2.0 technology. WCF can be configured to process "plain" XML data that is not wrapped in a SOAP envelope. WCF can also be extended to support specific XML formats, such as ATOM (a popular RSS standard), and even non-XML formats, such as JavaScript Object Notation (JSON).

Extensibility: The WCF architecture has a number of extensibility points. If extra capability is required, there are a number of entry points that allow you to customize the behavior of a service.

Relation between SOA and WCF

1. In SOA, a service must have End Points. WCF has all these end points: Address, Contract and Binding

2. Versioning of Services in WCF: In SOA, services can be versioned and you can host those services at new end points.

For example: You have a service named 'YourService' at end point “ep1”. Now you make enhancements in your service and launch a new service 'YourService2'. You can use it at another end point say "ep2". So the client who is consuming the service at end ep1 continues and at the other end, you have evolved your service by adding new ends ep2.

3. In SOA, the client who is consuming the service does not need to know how the implementation of the service is done. Services use Schemas to represent data and Contracts to understand behavior. They do not use language dependent types or classes in order to understand data and behavior. XML is used to define schemas and contracts.Same strategy is followed in WCF.

Advantages of WCF over older communication technologies:

1. WCF is interoperable with other services when compared to .Net Remoting, where the client and service have to be .Net.
2. WCF services provide better reliability and security in compared to ASMX web services.
3. WCF has integrated logging mechanism, changing the configuration file settings will provide this functionality. In other technology developer has to write the code.
4. WCF is faster than previous communication technologies by microsoft.
 

No comments:

Post a Comment

About the Author

I have more than 10 years of experience in IT industry. Linkedin Profile

I am currently messing up with neural networks in deep learning. I am learning Python, TensorFlow and Keras.

Author: I am an author of a book on deep learning.

Quiz: I run an online quiz on machine learning and deep learning.