Understanding Message Exchange Patterns
A Message Exchange Pattern (MEP) defines the shape of communication for a WCF operation: whether the client waits for a reply, sends and forgets, or opens a channel the service can call back through. WCF supports three MEPs — One-Way, Request-Reply, and Duplex — and the pattern for an operation is determined by the OperationContract attribute (IsOneWay), the presence of a return value or out/ref parameters, and whether the chosen binding supports duplex callbacks at all.
Cricket analogy: Choosing a MEP is like choosing how a captain communicates a field change: a shouted instruction to the fielder is one-way, a review referral to the third umpire that returns a decision is request-reply, and the walkie-talkie link between captain and coach during a strategic timeout that can interrupt either way is duplex.
Request-Reply: The Default Pattern
Request-Reply is the default MEP for any operation whose contract has a return type or out/ref parameters. The client sends a request message and blocks (or awaits, in async proxies) until the service returns a response message correlated back to the original by matching the reply's RelatesTo header to the request's MessageId. This pattern works with the most common bindings — BasicHttpBinding, WSHttpBinding, and NetTcpBinding — and gives the client a natural way to detect failures, since a SOAP fault can be returned as the reply.
Cricket analogy: Correlating a reply to its request is like a DRS review: the on-field umpire sends a specific query to the third umpire, and the response that comes back is matched to that exact delivery, not some earlier ball in the over.
One-Way Operations
Marking an operation with [OperationContract(IsOneWay = true)] tells WCF the client should not wait for any response: the method must return void, cannot declare out or ref parameters, and any exception thrown on the service side cannot be relayed back synchronously because there is no reply channel. The client's proxy call typically returns as soon as the message is handed to the transport, which means dispatch is not the same as guaranteed delivery — for durable, guaranteed one-way messaging you need a queued transport such as netMsmqBinding rather than relying on HTTP or TCP alone.
Cricket analogy: It's like a twelfth man running onto the field to deliver a drinks message to the batsman — the message is dropped off and the runner jogs back without waiting to see whether the batsman actually reads it.
Duplex and Choosing the Right Pattern
The Duplex MEP lets the service initiate calls back to the client over a callback channel, which requires a binding that supports it — WSDualHttpBinding or NetTcpBinding — plus a CallbackContract declared on the service contract. It is the right fit for scenarios like progress notifications, chat, or stock-ticker style push updates, where the server needs to reach the client without the client polling. Choosing among the three MEPs is ultimately a trade-off between simplicity (Request-Reply), throughput and fire-and-forget efficiency (One-Way), and interactive, event-driven communication (Duplex), each carrying different implications for session state, threading, and reliability.
Cricket analogy: Opting for a duplex-capable binding is like a team choosing to run a stump microphone feed both ways during a broadcast, versus just a simple post-match interview — it costs more setup but lets commentary and the players' reactions flow live in both directions.
[ServiceContract]
public interface IOrderService
{
// Request-Reply (default): client blocks for a return value
[OperationContract]
OrderConfirmation PlaceOrder(OrderRequest request);
// One-Way: fire-and-forget, must return void
[OperationContract(IsOneWay = true)]
void LogAuditEvent(AuditEvent evt);
}
[ServiceContract(CallbackContract = typeof(IOrderStatusCallback))]
public interface IOrderTrackingService
{
[OperationContract]
void SubscribeToOrder(int orderId);
}
public interface IOrderStatusCallback
{
[OperationContract(IsOneWay = true)]
void OnStatusChanged(int orderId, string newStatus);
}Correlation for Request-Reply and Duplex relies on SOAP message headers: every request carries a unique MessageId, and the corresponding reply (or callback) carries a RelatesTo header pointing back to it. This is how a WCF client proxy matches an asynchronous-looking network exchange to the specific call that initiated it, even when multiple calls are in flight concurrently.
- WCF defines three Message Exchange Patterns: One-Way, Request-Reply, and Duplex.
- Request-Reply is the default whenever an operation has a return value or out/ref parameters.
- One-Way operations must return void, cannot use out/ref parameters, and cannot synchronously propagate faults.
- Dispatch of a one-way message is not the same as guaranteed delivery; use netMsmqBinding for durable queued delivery.
- Duplex requires a CallbackContract and a binding that supports it, such as WSDualHttpBinding or NetTcpBinding.
- Correlation between requests, replies, and callbacks is done via MessageId and RelatesTo SOAP headers.
- Choosing the right MEP is a trade-off between simplicity, throughput, and interactivity.
Practice what you learned
1. Which MEP is used automatically when an OperationContract method has a non-void return type?
2. What restriction applies to an operation marked [OperationContract(IsOneWay = true)]?
3. Which binding is commonly used to guarantee durable delivery of one-way messages even if the service is temporarily offline?
4. What SOAP header does WCF use to match a reply message to the request that triggered it?
5. Which two elements are required to enable the Duplex MEP on a service contract?
Was this page helpful?
You May Also Like
Duplex Communication in WCF
Covers how WCF services push data back to clients using callback contracts, duplex-capable bindings, and session-aware instance management.
WCF vs Web API
Compares WCF's protocol-flexible, contract-first model against ASP.NET Web API's HTTP-first, resource-oriented approach, and when to choose each.
RESTful Services with WCF
Shows how to expose plain REST/JSON endpoints from a WCF service using webHttpBinding, WebGet/WebInvoke, and UriTemplate routing.
Related Reading
Related Study Notes in Microsoft Technologies
Browse all study notesWindows 10 / UWP Development Study Notes
.NET · 30 topics
Microsoft TechnologiesWindows Batch Scripting Study Notes
Batch · 30 topics
Microsoft TechnologiesMFC (Microsoft Foundation Classes) Study Notes
C++ · 30 topics
Microsoft TechnologiesSilverlight Study Notes
.NET · 30 topics
Microsoft TechnologiesXAML Study Notes
.NET · 30 topics
Microsoft TechnologiesWPF (Windows Presentation Foundation) Study Notes
.NET · 30 topics