.NET 3.0 comes with three main technologies in core: Windows Presentation Foundation, Windows Workflow Foundation and 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.
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.
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.
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.
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.
Other useful articles