100% Free Forever
AI-Powered Learning
Industry Expert Content
Certificates & Badges
Learn At Your Own Pace
.NET Framework

WCF Reliable Messaging

Learn how WCF's WS-ReliableMessaging support guarantees ordered, exactly-once (or at-least-once) message delivery over unreliable transports like HTTP.

Reliability and TransactionsAdvanced10 min readJul 10, 2026
Analogies

What Is WCF Reliable Messaging?

Reliable messaging in WCF implements the WS-ReliableMessaging (WS-RM) protocol, which guarantees that messages sent between a client and service arrive exactly once, in the order they were sent, even when the underlying transport (such as HTTP) provides no such guarantee on its own. Without reliable messaging, a dropped TCP connection or a transient network blip can silently lose a message, and the caller may never know. WS-RM introduces sequence numbers, acknowledgments, and retransmission so that both endpoints can detect gaps and recover without the application code having to implement its own retry logic.

🏏

Cricket analogy: It's like a scorer who numbers every ball bowled in an over so that if the radio commentary cuts out for a moment, the scorebook can still be reconstructed in the exact sequence the deliveries happened, rather than guessing which ball came before which.

The WS-ReliableMessaging Protocol

Under the hood, WS-RM establishes a reliable session identified by a sequence, and every message carries a sequence number within that session. The receiving endpoint sends back SequenceAcknowledgement messages listing which numbers it has received, and the sender retransmits anything not yet acknowledged after a timeout. WCF exposes this through binding elements: netTcpBinding and wsHttpBinding both support a <reliableSession> configuration element, and you can also compose a CustomBinding with a ReliableSessionBindingElement layered over a transport binding element such as httpTransport, giving you WS-RM over plain HTTP without WS-HTTP's SOAP security overhead.

🏏

Cricket analogy: It's like a third umpire's decision review system where every review request is logged with a unique number, and if the on-field signal fails to reach the broadcast van, the system flags the missing acknowledgment and resends the query.

xml
<system.serviceModel>
  <bindings>
    <wsHttpBinding>
      <binding name="reliableWsHttp">
        <reliableSession enabled="true"
                          ordered="true"
                          inactivityTimeout="00:10:00" />
        <security mode="Message" />
      </binding>
    </wsHttpBinding>
  </bindings>
  <services>
    <service name="OrderService.OrderProcessor">
      <endpoint address=""
                binding="wsHttpBinding"
                bindingConfiguration="reliableWsHttp"
                contract="OrderService.IOrderProcessor" />
    </service>
  </services>
</system.serviceModel>

Configuring Reliable Sessions

The <reliableSession> element takes three key attributes: enabled turns WS-RM on for the binding; ordered controls whether the service must deliver messages to the application in the exact sequence sent (true) or may deliver them as they arrive as long as none are lost (false); and inactivityTimeout defines how long the session can go without traffic before WCF tears it down and faults the channel. A reliable session is distinct from — but often paired with — a security session; enabling reliableSession does not by itself provide authentication or encryption, so you still configure <security> separately on the binding. Because WS-RM sessions carry state (sequence numbers, buffered unacknowledged messages) on both sides, they interact directly with InstanceContextMode.PerSession service instancing, since the reliable session's lifetime is what keeps a per-session service instance alive.

🏏

Cricket analogy: Setting ordered='true' is like a Test match innings where the scorer insists every over's balls are recorded strictly 1 through 6 in sequence, whereas ordered='false' is more like a T10 exhibition where the final tally matters but ball-by-ball sequence logging is relaxed.

Reliable sessions add protocol overhead (extra acknowledgment round-trips and buffered retransmission state on both endpoints), so they're best reserved for operations where message loss is unacceptable — such as multi-step order processing — rather than applied blanket across every low-value chatty endpoint.

Ordered Delivery and Message Buffering

When ordered='true', the receiving WCF runtime buffers out-of-sequence messages in memory until the missing predecessor arrives, then delivers them to the service operation in the correct order; this buffering is bounded by the channel's MaxReceivedMessageSize and related quotas, and a sender that gets far ahead of the receiver's acknowledgments risks the flow-control window forcing it to pause. Because retransmission and buffering consume memory and CPU on both client and service, WS-RM sessions are typically scoped to a bounded, business-critical exchange (like submitting a multi-part purchase order) rather than left open indefinitely; the inactivityTimeout exists precisely to reclaim these resources when a client disappears mid-conversation without a clean close.

🏏

Cricket analogy: It's like a TV director who holds a slightly delayed replay buffer so that if the ball-by-ball graphic overlay arrives late, the broadcast can still insert it into the correct spot in the feed rather than showing deliveries out of sequence.

Enabling reliableSession on a binding used by a service with InstanceContextMode.PerCall can be surprising: the reliable session itself requires session affinity to track sequence state, which effectively forces session-oriented behavior even though each business call still gets a fresh instance. Mixing this incorrectly with InstanceContextMode.PerCall and a load-balanced farm without sticky routing can cause session faults.

  • WS-ReliableMessaging guarantees ordered, non-duplicated delivery over unreliable transports using sequence numbers and acknowledgments.
  • Enable it via <reliableSession enabled="true"> on wsHttpBinding or netTcpBinding, or by composing a ReliableSessionBindingElement in a CustomBinding.
  • The ordered attribute controls whether messages must be delivered to the application in strict sequence or merely without loss.
  • inactivityTimeout reclaims session resources when a client abandons a reliable session without a clean close.
  • Reliable sessions are distinct from security sessions — you must still configure <security> separately for authentication and encryption.
  • Out-of-order messages are buffered in memory on the receiver until the missing predecessor arrives, bounded by message size quotas.
  • Reserve reliable messaging for bounded, business-critical exchanges rather than every chatty endpoint, since it adds real protocol overhead.

Practice what you learned

Was this page helpful?

Topics covered

#NETFramework#WCFWindowsCommunicationFoundationStudyNotes#MicrosoftTechnologies#WCFReliableMessaging#WCF#Reliable#Messaging#ReliableMessaging#StudyNotes#SkillVeris