Overview of Windows Communication Foundation (WCF)

Windows Communication Foundation (WCF) is a unified programming model for building service-oriented applications. WCF provides a rich set of features for building distributed systems, including interoperability, security, transaction management, and reliable messaging. It enables applications to communicate with each other regardless of the platform, operating system, or programming language they are built with.

This documentation covers WCF as part of the .NET Framework 3.5, a widely adopted version that introduced significant advancements in service development.

Key Concepts in WCF

Getting Started with WCF

Creating your first WCF service involves defining a service contract, implementing the service, and configuring an endpoint. WCF offers various templates and wizards in Visual Studio to simplify this process.

A typical service creation workflow includes:

  1. Defining the IServiceContract interface.
  2. Implementing the service class that inherits from the contract.
  3. Configuring the service host and endpoints (usually in App.config or Web.config).
  4. Creating a client proxy to consume the service.

Common Scenarios and Use Cases

Core Components and Technologies

Service Contracts

Service contracts are interfaces that specify the operations a service exposes. The [ServiceContract] attribute marks an interface as a service contract, and the [OperationContract] attribute marks methods that are callable by clients.

[ServiceContract]
public interface IMyService
{
    [OperationContract]
    string GetData(int value);
}

Data Contracts

Data contracts define the structure of data passed between clients and services. The [DataContract] attribute is applied to classes, and the [DataMember] attribute is applied to properties or fields to make them serializable.

[DataContract]
public class MyData
{
    [DataMember]
    public int Value { get; set; }

    [DataMember]
    public string Name { get; set; }
}

Bindings and Transport Protocols

WCF supports various bindings to cater to different communication needs:

Security in WCF

WCF offers robust security features, including:

Note: While .NET Framework 3.5 was a landmark release, modern development often leverages .NET Core or .NET 5+ which offer WCF capabilities through community projects like CoreWCF or alternative technologies like ASP.NET Core Web API.