2.1 Fundamentals
1. Windows Communication Foundation
Windows Communication Foundation (WCF) is a framework developed by Microsoft for building service-oriented applications. It allows developers to build secure, reliable, and scalable distributed systems by providing a unified programming model for building and deploying networked services.
1 Key Features of WCF
1. Interoperability: WCF is designed to interoperate with services built on other platforms, thanks to its support for various industry standards like SOAP, WS-*, and REST.
2. Service-Oriented Architecture (SOA): WCF supports SOA principles, making it easier to create loosely coupled services that can be composed and orchestrated into more complex workflows.
3. Multiple Transport Protocols: WCF supports multiple communication protocols, including HTTP, TCP, MSMQ, and named pipes. This flexibility allows developers to choose the most appropriate protocol for their application’s requirements.
4. Security: WCF provides a range of security features, including message encryption, authentication, and authorization. It supports various security standards and allows for secure communication over different protocols.
5. Extensibility: WCF is highly extensible, allowing developers to customize the runtime behavior and add new communication capabilities.
6. Reliable Messaging: WCF includes built-in support for reliable messaging, ensuring that messages are delivered even in the presence of network failures.
2. Importance of WCF in Distributed Computing
1. Communication Abstraction: WCF abstracts the underlying communication mechanisms, allowing developers to focus on business logic rather than the complexities of networking. This is crucial for building scalable distributed systems.
2. Interoperability: With support for standard protocols and data formats, WCF facilitates communication between services built on different platforms and technologies, making it a key tool for building interoperable distributed systems.
3. Security and Reliability: WCF provides robust security features and reliable messaging, which are critical for distributed systems that need to operate over insecure or unreliable networks.
4. Scalability: WCF’s support for different communication patterns (such as request/reply, one-way, and duplex) and its ability to host services in various environments (such as IIS, Windows Services, or self-hosted) contribute to building scalable distributed systems.
5. Flexibility and Extensibility: WCF’s flexible configuration and extensibility make it suitable for a wide range of applications, from simple web services to complex, enterprise-level distributed systems.
2. CORBA ?
Common Object Request Broker Architecture (CORBA) is a standard defined by the Object Management Group (OMG) for enabling communication between objects in a distributed computing environment, regardless of the programming language in which they were written or the platforms on which they are running. CORBA achieves this by specifying a set of protocols and services that facilitate object communication and interoperability.
1. Key Features of CORBA
1. Object Request Broker (ORB): The core component of CORBA, the ORB, acts as a middleware that handles communication between client and server objects. It manages requests and responses, handles object references, and performs necessary data conversions.
2. Interface Definition Language (IDL): CORBA uses IDL to define the interfaces that objects expose. IDL is language-agnostic, enabling objects written in different programming languages to communicate.
3. Interoperability: CORBA supports interoperability between different platforms and languages by providing standard protocols, such as IIOP (Internet Inter-ORB Protocol).
4. Services and Facilities: CORBA provides a set of standard services (e.g., naming, event, transaction) and facilities (e.g., messaging) that support distributed object interactions.
5. Platform Independence: CORBA objects can be implemented in any language and run on any platform, as long as they conform to the CORBA standard.
2. Relationship Between CORBA and WCF
While both CORBA and WCF serve the purpose of enabling communication in distributed systems, they come from different backgrounds and have some key differences:
1. Technology Origin and Standards:
- CORBA: Developed by the OMG, CORBA is a vendor-neutral, platform-independent standard designed for cross-language and cross-platform interoperability.
- WCF: Developed by Microsoft, WCF is a .NET framework that primarily supports interoperability within the .NET ecosystem but also adheres to industry standards like SOAP and WS-*, allowing for some level of cross-platform communication.
2. Communication Model:
- CORBA: Focuses on an object-oriented model where distributed objects interact by invoking methods on each other, much like local objects.
- WCF: Is service-oriented, focusing on the exchange of messages between services. It supports various communication patterns, including request/reply, one-way, and duplex.
3. IDL vs. Contracts:
- CORBA: Uses IDL to define the interface of objects in a language-agnostic way.
- WCF: Uses .NET interfaces and attributes to define service contracts, which are typically tied to .NET languages.
4. Interoperability:
- CORBA: Is inherently designed for interoperability between different languages and platforms.
- WCF: Can interoperate with other platforms and technologies through support for standard protocols like SOAP, but it is primarily geared towards .NET applications.
5. Security and Reliability:
- Both CORBA and WCF offer various security and reliability features, though WCF has more built-in support for modern web standards and practices.
CORBA and WCF are both technologies for building distributed systems, but they are rooted in different ecosystems and have different focuses. CORBA is a cross-platform, language-agnostic standard, while WCF is a Microsoft-centric framework with strong integration into the .NET ecosystem. Both serve to enable communication and interoperability in distributed systems, albeit with different approaches and use cases.
3. Simple Application Using WCF
Creating a simple WCF (Windows Communication Foundation) application involves defining a service contract, implementing the service, hosting the service, and creating a client to consume the service. Following is the walk through of a simple calculator service.
3.1 Define the Service Contract
Create a Visual Studio Class Library C# (.Net Framework)
Project. Name the project as Interface
. Add the Assembly reference for System.ServiceModel
in the project.
The service contract specifies the operations that the service provides. We use the [ServiceContract]
and [OperationContract]
attributes to define the contract.
using System.ServiceModel;
namespace CalculatorInterface{ [ServiceContract] public interface ICalculator { [OperationContract] double Add(double a, double b);
[OperationContract] double Subtract(double a, double b); }}
3.2 Implement the Service
Create a Visual Studio Console App (.Net Framework)
Project. Name the project as ServerApp
. Add the Assembly reference for System.ServiceModel
in the project. Add the project reference to the project Interface
created above.
Implement the service contract by creating a class that implements the interface.
using CalculatorInterface;
namespace CalculatorNS{ public class CalculatorService : ICalculator { public double Add(double a, double b) { return a + b; }
public double Subtract(double a, double b) { return a - b; } }}
3.3 Host the Service
In the ServerApp
project, the service can be hosted in various environments like IIS, Windows Services, or a console application. For simplicity, we’ll use a console application.
using System;using System.ServiceModel;
public class Program{ public static void Main(string[] args) { //Start the server Console.WriteLine("Welcome"); var tcp = new NetTcpBinding();
// Create the ServiceHost ServiceHost host = new ServiceHost(typeof(CalculatorService));
// Bind the interface (Define the base address for the service) host.AddServiceEndpoint(typeof(ICalculator), tcp, "net.tcp://localhost:8081/Calculator");
// Open the host host.Open();
Console.WriteLine("Service is running..."); Console.WriteLine("Press Enter to exit."); Console.ReadLine();
// Close the host host.Close(); }}
In this code:
- We define the base address as
"net.tcp://localhost:8081/Calculator"
. - We create an instance of
NetTcpBinding
and add a service endpoint. - We optionally enable metadata exchange (MEX) over TCP, which is useful for generating client proxies.
3.4 Creating the Client
Create a Visual Studio Console App (.Net Framework)
Project. Name the project as ClientApp
. Add the Assembly reference for System.ServiceModel
in the project. Add the project reference to the project Interface
created above.
using System;using System.ServiceModel;
public class Program{ public static void Main(string[] args) { // Define the service endpoint string baseAddress = "net.tcp://localhost:8081/Calculator";
// Create the NetTcpBinding NetTcpBinding binding = new NetTcpBinding();
// Create the channel factory ChannelFactory<ICalculator> factory = new ChannelFactory<ICalculator>(binding, baseAddress);
// Create the channel ICalculator calculator = factory.CreateChannel();
// Use the service double result = calculator.Add(1, 2); Console.WriteLine($"1 + 2 = {result}");
result = calculator.Subtract(5, 3); Console.WriteLine($"5 - 3 = {result}");
// Close the channel ((IClientChannel)calculator).Close(); factory.Close();
Console.ReadLine(); }}
In this code:
- We define the base address and create an instance of
NetTcpBinding
. - We create a
ChannelFactory
with the binding and endpoint address. - We create the channel and use the service methods.
3.5 Run the Applications
- Run the Service Host: Start the console application that hosts the WCF service.
- Run the Client: Start the console application that consumes the service.
When the client runs, it should display the results of the operations provided by the ICalculator
Interface.