AspAlliance.com LogoASPAlliance: Articles, reviews, and samples for .NET Developers
URL:
http://aspalliance.com/articleViewer.aspx?aId=1103&pId=-1
Introduction to Windows Communication Foundation
page
by Keyvan Nayyeri
Feedback
Average Rating: 
Views (Total / Last 10 Days): 39648/ 80

Overview

.NET 3.0 comes with three main technologies in core: Windows Presentation Foundation, Windows Workflow Foundation and Windows Communication Foundation.  In past tutorials I introduced Windows Presentation Foundation and XAML and now I want to try things for Windows Communication Foundation.

Windows Communication Foundation (WCF), codenamed Indigo in Microsoft, is the last generation of service oriented technologies for development.  It provides all the latest means to help developers build service oriented applications.  The result of service oriented design is a distributed system which runs between services and clients.  Windows Communication Foundation is Microsoft infrastructure for Service Oriented architecture.

You have probably worked with Web Services in .NET 1.x or 2.0 and may have some experiences with Remoting.  Windows Communication Foundation is an enhanced technology to provide the same functionality with better features and reduces the time to develop a distributed system.  Web Services and Services are not identical.  One main difference is Web Services use HTTP protocol, but Services can use any protocol and this is an important difference.

The first part of this article is a Windows Communication Foundation tutorials; I introduce this new technology, its architecture, programming model, service orientated design and give some other necessary information to start with this technology.

Service Orientation

Almost all developers know something about Object Oriented Programming (OOP) which has been a common way to build software for a long time.  But what is Service Oriented architecture?

In recent years, development moved from building centralized local systems to distributed systems which run on several places.  Each part of these systems are hosted somewhere and provide some services.  The idea of having services to answer to common needs through the web became serious and development technologies answered to this need by providing Web Services in their core, but day after day distributed systems became more common and the idea of Service Orientation (SO) was born.

Service Orientation is a complement to Object Orientation.  It means you will not kick Object Orientation out to use Service Orientation.  Service Orientation uses Object Orientation in its core, but there are some distributed scenarios that can be viewed by Object Orientation so you use Service Orientation to describe these scenarios.

In Service Orientation you think different and describe things via services and divide your system into smaller parts which run as services.  These services can communicate with others via messages.  In each service you can apply Object Orientation to accomplish goals of that service.  One important benefit of Service Orientation is here because you can use different technologies and platforms to design a service by using Object Orientation then use universal formats to build messages and start communication between different pieces of your system.

There are four principles in Service Orientation (you may see them as tenets on other resources):

·         Boundaries are explicit.

·         Services are autonomous.

·         Services share schema and contract, not class.

·         Service compatibility is determined based on policy.

You can read more about these fundamentals (they are important principles) on MSDN.

Generally, you have to change your point of view in Service Oriented design, but this should not change your view for Object Oriented Programming.  You should get enough experience to divide a system to logical independent services then choose appropriate platform to build each piece.  Thankfully, Microsoft helps you in all stages and you can use powerful Microsoft technologies to build your distributed software.

Service Oriented Architecture (SOA) is a concept beyond the scope of these tutorials.  I recommend you to read good books about Service Oriented Architecture to learn more about it.  Having a good understanding of this architecture is an important requirement to be success in this field.

Advantages

Windows Communication Foundation has some important enhancements in comparison with preceding technologies.

·         It merges all older separate technologies in one place and allows you to do things easier.

·         It has rich communication capabilities.

·         It comes with many powerful and ready to use enterprise features.

·         It can be integrated with other technologies and has great interoperability.

Fundamental Concepts

In Windows Communication Foundation your services can have communication with clients by sending and receiving messages (Figure 1).

Figure 1

Windows Communication Foundation consists of three main concepts:

·         Services: Programs that respond to clients.  They can send or receive messages.

·         Clients: Programs that ask for a service.  They can send or receive messages.

·         Intermediaries: Programs that sit between services and clients (Figure 2).  They can work as a firewall or can rout messages.  In all cases neither services nor clients need to be aware of intermediaries.

Figure 2

Most of the time, developers deal with services and clients and do not need to work much with intermediaries.

Services and clients have communications by sending and receiving messages, but again most of the time you do not work directly with messages and Windows Communication Foundation does this for you.

Here you should learn that a service can have more than one client (Figure 3) and each service can be a client of another service itself (Figure 4).

Figure 3

Figure 4

Each of these main concepts has important concepts in its core or beside it.  Some other concepts that you will deal with frequently are Channels, Bindings, Contracts, Behaviors, Addresses and Endpoints.

In the second part of these tutorials I will describe all important concepts in some details.

Architecture

Architecture of Windows Communication Foundation consists of five layers.  These layers from top to down are:

·         Application: In this level application is located.

·         Contracts: In the second layer service, data and message contracts as well as bindings and policies are present.  In this level services describe themselves to clients.

·         Runtime: Behaviors are located in this layer.  Runtime layer loads all services.

·         Messaging: Different types of channels as well as encoders are here.  This layer enables communications for services.

·         Hosting: This layer is where host services in different manners, but there are two common ways to host a service.  You can host a service in Internet Information Services (IIS) which is easier than the second approach and starts and stops your services automatically.  The second approach is to create executable files (.EXE) for services and start and stop them manually by writing more codes.

This layering allows developers to work on Windows Communication Foundation with different skills because each layer needs different skills.

Programming Model

Windows Communication Foundation has simple and easy to write/understand codes.  It has many APIs, but beside this only a small amount of these API's is common.

There are three programming approaches in Windows Communication Foundation:

·         Imperative: You use programming codes in different languages to accomplish a task.

·         Configuration Based: You use configuration files to do things.

·         Declarative: You use attributes to declare something.

In general, you will declare contracts and behaviors using attributes, configure endpoints, security and some other settings in configuration files and will implement service methods logic in codes.

On the other hand, you can use typed services and untyped services.  In typed services you pass normal objects and data types and/or get normal objects and data types, but in untyped services you pass and get messages to work directly with messages at a lower level.

Installation

Installation of Windows Communication Foundation and its development tool is easy and consists of these steps:

·         Download and install .NET Framework 3.0 RTM.  I also strongly recommend you to download and install WinFX SDK as well.  After this step you have all necessary API's to run Windows Communication Foundation.

·         Download and install Visual Studio 2005xtensions for .NET Framework 3.0 WCF and WPF).  After installing this package, you will have new project templates in your Visual Studio to start developing for Windows Communication Foundation (Figure 5 and Figure 6).

Figure 5

Figure 6

References

Here is a list of available books about Windows Communication Foundation.

·         Microsoft Windows Communication Foundation: Hands-on written by Craig McMurtry, Marc Mercuri and Nigel Watling (Sams)

·         Programming WCF Services written by Juval Lowy (O'Reilly)

·         Pro WCF: Practical Microsoft SOA Implementation written by Chris Peiris, Dennis Mulder, Amit Bahree, Aftab Chopra, Shawn Cicoria and Nishith Pathak (APress)

·         Programming INDIGO written by David Pallmann (Microsoft Press)

And here is a list of online resources and communities about Windows Communication Foundation.

·         Microsoft Windows Communication Foundation Community

·         Windows Communication Foundation homepage on MSDN

·         Windows Communication Foundation Forum

Summary

In this article I introduced Windows Communication Foundation as Microsoft fundamental for Service Oriented architecture and building distributed systems.  I gave basic information about Service Oriented Architecture (SOA), fundamental concepts, architecture and programming model.  Finally, I gave a list of useful resources for further reading.  Keep looking for new parts of these tutorials.  I will try to cover more and more about this great new technology in .NET 3.0.


Product Spotlight
Product Spotlight 

©Copyright 1998-2024 ASPAlliance.com  |  Page Processed at 2024-05-04 1:37:26 AM  AspAlliance Recent Articles RSS Feed
About ASPAlliance | Newsgroups | Advertise | Authors | Email Lists | Feedback | Link To Us | Privacy | Search