Windows Communication Foundation (Code named Indigo) is a programming platform and runtime system for building, configuring and deploying network-distributed services. It is the latest service oriented technology; Interoperability is the fundamental characteristics of WCF. It is unified programming model provided in .Net Framework 3.0. WCF is a combined features of Web Service, Remoting, MSMQ and COM+. WCF provides a common platform for all .NET communication.
WCF is meant for designing and deploying distributed applications under service-oriented architecture (SOA) implementation. Services are loosely coupled to each other. Services typically have a WSDL interface (Web Services Description Language) that any WCF client can use to consume the service, regardless of which platform the service is hosted on. WCF implements many advanced Web services (WS) standards such as WS-Addressing, WS-ReliableMessaging and WS-Security.
Features of WCF:
WCF includes the following set of features.
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. For more information about how to implement different message exchange patterns using WCF.
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.
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.
A WCF client connects to a WCF service via an Endpoint. Each service exposes its contract via one or more endpoints. An endpoint has an address (which is a URL specifying where the endpoint can be accessed) and binding properties that specify how the data will be transferred. Interaction between WCF endpoint and client is done using a SOAP envelope. SOAP envelopes are in simple XML form that makes WCF platform independent.When a client wants to access the service via an endpoint, it not only needs to know the contract, but it also has to adhere to the binding specified by the endpoint. Thus, both client and server must have compatible endpoints. Behaviors
Behaviors are types that modify or extend service or client functionality. Behaviors allow the developer to create custom processing, transformation, or inspection that is applied to messages as they are sent or received. Some examples of uses for behaviors are:
- Controlling whether metadata is published with a service
- Adding security features to a service, such as impersonation, authorization, or managing tokens
- Recording information about messages, such as tracking, tracing, or logging
- Message or parameter validation
- Invoking all additional operations when messages are received–such as notifying users when certain messages arrive
- Behaviors implement the IServiceBehavior interface for service extensions, the IEndpointBehavior for endpoints, the IContractBehavior interface for service contracts, or the IOperationBehavior for operations. Service behaviors are used for message processing across a service, rather than processing that would be specific to a single operation.
The contract is a platform-neutral and standard way of describing what the service does. WCF defines four types of contracts:
Describe which operations the client can perform on the service.
There are two types of Service Contracts.
ServiceContract – This attribute is used to define the Interface.
OperationContract – This attribute is used to define the method inside Interface.
Define which data types are passed to and from the service. WCF defines implicit contracts for built-in types such as int and string, but we can easily define explicit opt-in data contracts for custom types.
There are two types of Data Contracts.
DataContract – attribute used to define the class
DataMember – attribute used to define the properties.
If DataMember attributes are not specified for a properties in the class, that property can’t be passed to-from web service.
Define which errors are raised by the service, and how the service handles and propagates errors to its clients.
Allow the service to interact directly with messages. Message contracts can be typed or untyped, and are useful in interoperability casxes and when there is an existing message format we have to comply with.
Activation and Hosting
Services can be hosted or executed, so that it will be available to everyone accessing from the client. WCF service can be hosted by following mechanism
- Internet information Service provides number of advantages if a Service uses Http as protocol. It does not require Host code to activate the service, it automatically activates service code.
- Windows Activation Service
- (WAS) is the new process activation mechanism that ships with IIS 7.0. In addition to HTTP based communication, WCF can also use WAS to provide message-based activation over other protocols, such as TCP and named pipes.
- WCF service can be self hosted as console application, Win Forms or WPF application with graphical UI.
- Windows Service
- WCF can also be hosted as a Windows Service, so that it is under control of the Service Control Manager (SCM).