WCF Terms and Concepts
Explore the fundamental building blocks and terminology of Windows Communication Foundation (WCF) in .NET Framework 3.5.
Service (Services)
A service is a unit of functionality exposed to other applications. In WCF, a service is typically represented by a class that implements one or more service contracts. It defines the operations that can be invoked by clients.
- Service Contract: Defines the operations that a service exposes.
- Service Implementation: The actual code that implements the operations defined in the service contract.
Endpoint
An endpoint is the intersection of an address, a binding, and a contract. It's how a client communicates with a service. Every WCF service exposes one or more endpoints.
- Address: Specifies the location where the service can be accessed (e.g., a URI).
- Binding: Defines the communication protocol (e.g., HTTP, TCP), message format (e.g., SOAP, binary), and security mechanisms used for communication.
- Contract: The set of operations the endpoint supports.
Example of an endpoint configuration:
<endpoint address="http://localhost:8080/MyService"
binding="basicHttpBinding"
contract="IMyService" />
Binding
A binding specifies how clients and services communicate. It dictates the transport protocol, message encoding, and security settings. WCF provides several built-in bindings, and you can also create custom ones.
basicHttpBinding
: For interoperability with non-WCF clients using HTTP and SOAP.wsHttpBinding
: For reliable, secure communication using WS-* standards over HTTP.netTcpBinding
: For high-performance, secure communication between WCF services over TCP.netNamedPipesBinding
: For inter-process communication on the same machine.
Contract (Operation Contract, Message Contract, Data Contract)
Contracts define the "shape" of a WCF service. They specify the operations, the format of messages, and the structure of data exchanged.
- Service Contract: Declares the operations available on a service. Marked with the
[ServiceContract]
attribute. - Operation Contract: Defines a specific operation within a service contract. Marked with the
[OperationContract]
attribute. - Data Contract: Defines the structure of data types that can be passed as parameters or return values. Marked with the
[DataContract]
attribute. - Message Contract: Allows fine-grained control over the SOAP message structure, including headers and body. Marked with the
[MessageContract]
attribute.
Example of a Data Contract:
[DataContract]
public class Customer
{
[DataMember]
public int Id { get; set; }
[DataMember]
public string Name { get; set; }
}
Message
The unit of data exchanged between a client and a service. In WCF, messages are typically SOAP messages, but can also be plain XML or binary.
Host
The process or environment where a WCF service is running. Services can be self-hosted, hosted in IIS, or hosted in Windows Services.
Channel & Channel Stack
WCF uses a channel architecture to handle communication. A channel is an object that processes messages. A channel stack is a series of channels that process messages for a specific endpoint.
Hosting (Self-Hosting, IIS Hosting, Windows Service Hosting)
The mechanism by which a WCF service is made available for clients to connect to. Each hosting model has its own setup and management requirements.
Interoperability
WCF's ability to communicate with services and clients built on different platforms and technologies, often achieved through standards like SOAP and WS-*.