Windows Communication Foundation Article Index for
Windows
Website Links For
Windows
 

Information About

Windows Communication Foundation




Windows Communication Foundation, sometimes shortened to just '''WCF''', previously codenamed ''Indigo'', is a new communication subsystem to enable applications, in one machine or across multiple machines connected by a network, to communicate. It is a part of WinFX - the new .NET based Windows API to succeed Win32 with the release of Windows Vista . It will also be available for Windows XP and Windows Server 2003 . WCF applications can be developed in any language which can target the .NET runtime.

WCF programming model unifies Web Services , .NET Remoting , Distributed Transactions , and Message Queues into a single Service-oriented Programming model for Distributed Computing . It is intended to provide the Rapid Application Development methodology to the development of Web Service s, with a single API for Inter-process Communication in a local machine, LAN , or over the Internet . WCF runs in a sandbox and provides the enhanced security model all .NET applications provide.

WCF uses SOAP messages for communication between two processes, thereby making WCF based applications interoperable with any other process that communicates via SOAP messages. When a WCF process communicates with a non – WCF process, XML based encoding is used for the SOAP messages but when it communicates with another WCF process, the SOAP messages are encoded in an optimized Binary format, to optimize the communication. Both the encodings conform to the data structure of the SOAP format, called ''Infoset''.

On January 18, 2006, Microsoft released a CTP of WinFX runtime components and a Go-Live license for WCF and WinWF . Components made available include the WinFX Runtime Components, WinFX SDK, and Visual Studio Extensions for Workflow, and Visual Studio "Orcas" CTP Development tools for WinFX. Server applications based on this technology can now be used in production development environments with the acquisition of a free license. However, as this is still under development, considerable care should be taken in determining if production use of the tool is appropriate for any development product.


SERVICE ORIENTED ARCHITECTURE

WCF uses the Service Oriented Architecture , where the Distributed Applications provide some Service , and the Clients contact these processes to consume the services. A client can consume more than one service; similarly a service can provide service to more than one client. Services expose an Interface , defined in XML, to which any WCF client can connect to, irrespective of which platform the server was designed in.


WCF SERVICE

A WCF Service is composed of three parts – a ''Service'' class that implements the service to be provided, a ''host environment'' to host the service, and one or more ''endpoints'' to which clients will connect to. All communications with the WCF service will happen via the endpoints. The endpoints specify a ''Contract'' that defines which methods of the Service class will be accessible via the endpoint; each endpoint may expose a different set of methods. The endpoints also define a ''binding'' that specifies how a client will communicate with the service and the address where the endpoint is hosted.

WCF provides Windows Activation Services which can be used to host the WCF service. Otherwise the WCF service can also be hosted in IIS or in any process by using the Service Host class, which is provided by WCF.


Defining WCF services

A WCF service class implements some service as a set of methods. In addition, it implements at least one ''Service Contract'' which defines the operations that the service does. It may also optionally implement ''Data Contracts'' which define what sort of data is worked upon by the exposed operations.

Contracts are defined using .NET attributes. Any class that is to be exposed as a WCF service must be marked with ''ServiceContract'' attribute, and all methods that a client can invoke using SOAP messages must be marked with ''OperationContract'' attribute. The attributes automatically generate WSDL descriptions for the exposed methods, which can be then accessed by clients, or advertised to clients.

A service can also employ multiple Service Contracts. This can be done by defining multiple .NET interfaces, each defining a Service Contract. The service class can then implement all the interfaces.

All Service Contracts have an associated Data Contract which defines the data that the service works on. If the data required by the service and the returned result is of simple types, like integers, doubles etc, then the Data Contract is defined automatically by WCF. But, if the data is of a complex type like an object or a struct, then the Data contract must be explicitly defined. Data contracts specify how the data is serialized and de-serialized.

A Data contract is defined by using a DataContract attribute on a class or structure. The members of the data structure which will be used by the service needs to be marked with a DataMember attribute. Only the members marked with DataMember attribute will be transferred between the service and its client via SOAP messages.

The behavior of the Service in general and the operations in particular can be controlled using the ''ServiceBehavior'' and the ''OperationBehavior'' attributes respectively. The ServiceBehavior attribute has different properties which control the properties of the service. The ''ConcurrenyMode'' property specifies whether the service will be concurrent, i.e., whether it will support simultaneous clients or not. Similarly, the ''InstanceMode'' property specifies whether a new instance of the service will be created for each call or whether all calls from same client will be serviced by a single instance.


Defining endpoints

A WCF client connects to a WCF service via an endpoint. Each Service contract is exposed via an endpoint. An endpoint also has an address, which is a URL specifying where the endpoint can be accessed, and a binding that specifies how the data will be transferred between the service and its client. Biding 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. When a client wants to access the service via an endpoint, it has to adhere to the binding specified by the endpoint.


COMMUNICATION WITH THE SERVICE

A client can communicate with WCF service using either RPC based mechanism where the service can use invoke the service as a method call. Any call to the service will be blocking, that is will halt the execution of the client till the service processes the request. The client has to connect to a service using a ''proxy'' Object , which is connected to the specified endpoint of the service and abstracts the service as an object. All method calls to the proxy object will be routed to the service and the proxy will return the results returned by the service to the caller.

WCF handles creating the local proxy. It retrieves from the endpoint the WSDL definition of the endpoint and creates the proxy which will communicate the data for the service using the protocol specified by the binding of the endpoint. It also has to convert the data returned by the service into a form expected by the caller.

WCF also supports non-blocking calls. It can also use the services by passing messages which send the data to be used by the service. Communicating using messages does not require the use of proxy object. The returned data will also be returned using a message. The application will still be blocked till the service returns the result. To make use of non-blocking messaging, Message Queues need to be used to handle the delivery and receipt of the messages. Message queues will also allow an application to work even if the service is temporarily down, with the knowledge that the request will be serviced when the server comes up again.


SEE ALSO



EXTERNAL LINKS