Friday, September 21, 2012

Windows Communication Foundation - Basics

I had a presentation on WCF (Windows Communcation Foundation) basics today in office. I walked through the basics mostly. 

Here is the plan followed in the presentation.

  1. Introduction
  2. Service Oriented Applications (SOA)
  3. Distributed Technologies - Evolution
  4. Purpose of WCF
  5. WCF Architecture
  6. WCF - Bindings
  7. WCF - Key classes in development




1. Introduction
Presented the different definitions from the authors about WCF. Following are the two definitions got from the authors.

"Windows Communication Foundation is a programming platform and runtime system for building, configuring and deploying network-distributed services."

"Windows Communication Foundation (WCF) is a framework for building service-oriented applications"

More details will be covered in later sections.

2. Service Oriented Applications (SOA)
Explained the definitions of "Service" and "SOA". Here are they...
  Service:  
          a. work done by one person or group that benefits another
          b. A Component capable of performing a task

These are the general definitions/meanings from the English dictionary. The same will be applied to the Services created in the software. 

   SOA: "A set of components which can be invoked, and whose interface descriptions can be published and discovered"

We can compare the services in the software with the following example.
 "A Car decor company provides a set of services to the cars, he will expose his list of services through some ads, but will not show their internal process of work". Similarly, Service is a component which can be invoked and whose interface descriptions can be published.

The programming models were evolved from Procedural model to Object Oriented to Service oriented model today.

2.1. SOA and WCF
I have explained the four design principles of "SOA" which are known as "Four Tenents of Service Orientation". 
     a. Boundaries are explicitApplications and services communicate by sending messages to each other. You should not make any assumptions about how a service processes a request or how a client application handles any response to a request. Following this principle can help to remove dependencies between services and client applications. Additionally, sending and receiving messages has an associated cost in terms of communications. You should design the operations that services implement with this in mind, and ensure that clients call services only when necessary.

     b. Services are autonomous. If you are building an application based on services, you might not have control over every service you are using, especially Web services hosted outside of your organization. The location of a Web service might change, or a service might be temporarily taken off-line for maintenance or other reasons. You should design your solutions to be loosely coupled, so that they can tolerate these changes and continue running even if one or more services are unavailable.

     c. Services share schemas and contracts, not classes or types. Services publish information about the operations that they implement and the structure of the data that they expect to send and receive. Clients use this information when communicating with the service. You should design contracts and schemas to define the interfaces that your services expose. This can reduce the dependencies that clients have on a particular version of your services. Services can change and evolve over time, and a new version of a service might appear superseding a previous version. If a service is updated, it should maintain compatibility with existing clients by continuing to implement existing contracts and send messages that conform to existing schemas. If you need to modify a service and provide additional functionality, you can add contracts and schemas that extend the original capabilities of the service while retaining the existing contracts and schemas. Older client applications should continue to work unchanged.

     d. Compatibility is based on policy. The schemas and contracts exposed by a service define the “shape” of the service but not the nonfunctional requirements that a client attempting to access the service must fulfill. For example, a service might have security requirements that state that clients must connect to it in a particular manner and send and receive messages by encrypting data in a specific way. This is an example of policy.

WCF has been designed with these principles. 

3. Distributed Technologies - Evolution
Explained about the evolution of the various distributed technologies over the time till now. Following are some of the distributed technologies used.

  • Pipes and Sockets - This is very low level mechanism and using it required a good understanding of how networks work.
  • Component Object Model (COM) - Microsoft developed COM as mechanism for communicating between applications and components running on the Windows platform. Microsoft originally designed COM to enable communications between components and applications running on the same computer. 
  • DCOM - COM was followed by Distributed COM, enabling the applications running on other computers over the network.
  • .Net Remoting
  • Enterprise Services
  • COM+ - COM was combined with the Microsoft Transactions server.
  • MSMQ
  • Web Services 
  • Web Services Enhancements (WSE)


4. Purpose of WCF?

The purpose of WCF is to provide a unified programming model for many of these technologies, enabling you to build applications that are as independent as possible from the underlying mechanism being used to connect services and applications together

WCF does not replace any particular technology, but it provides uniform platform to use many technologies like web services, MSMQ, windows services etc.

5. WCF - Architecture
WCF services typically deals with the concept called "EndPoint". End point is the combination of ABC.
 A - Address (where is the service deployed?)
 B - Binding (How can the service be used?). Various bindings available explained in later section.
 C - Contract (What does service provide?)


Following is the architecture of WCF


6. WCF - Bindings 

Explained the partial list of bindings available for WCF and their respective properties.

7. WCF - Key classes
We have four main classes to be used in WCF service development. All these classes are available in the namespace System.ServiceModel.

  1. ServiceContractAttribute - This is used to decorate the interface which will be exposed from the service.
  2. OperationContractAttribute - This is used to decorate the methods/operations of the interface.
  3. DataContractAttribute - This is used to decorate the entity objects used in the service.
  4. DataMemberAttribute - This is used to decorate the properties of the entity objects in the service
In my next post, will explain WCF with examples. Hope the basics of WCF help someone...

Thank you,
Raheem MA     

No comments:

Post a Comment