Message Framing, Part 1

Message framing is the breaking up of a stream of data into demarcated units called messages. Some protocols, such as HTTP, natively include a notion of message framing. Other protocols, such as TCP, don't natively include a notion of message framing and need to be augmented with one to be used in a messaging system. WCF includes a message framing protocol called .Net Message Framing for use with transports that don't natively support messaging. This framing protocol is used with the TCP transport to create NetTcp and the MSMQ transport to create NetMsmq. The classes used by the message framing protocol aren't public but after reading this series you should know enough about how the protocol works to put together your own implementation that does most of .Net Message Framing.

The basic operation of .Net Message Framing is to first exchange some metadata about how messages will be exchanged and then to exchange the messages themselves. The metadata includes information such as the version of the framing protocol being used and the algorithm for encoding the messages. The messages can be transmitted in a variety of formats and, if something goes wrong with the exchange, transmission can be aborted to allow the connection to be reused.

The message framing protocol works by sending a series of typed records. Each record is prefixed with a single byte that indicates the record type. There are a few different legal orders of records depending on which mode the message framing protocol is being used in. Here are all of the possible record types along with the type number of each record. Next time, I'll start going into these record types to explain how the message exchange metadata works.

  • 0- Version
  • 1- Mode
  • 2- Via
  • 3- Known Encoding
  • 4- Extensible Encoding
  • 5- Unsized Envelope
  • 6- Sized Envelope
  • 7- End
  • 8- Fault
  • 9- Upgrade Request
  • 10- Upgrade Response
  • 11- Preamble Ack
  • 12- Preamble End
Comments (5)

  1. Hi Nicholas,

    it looks like you are back to the basics. Any connection to AMQP?

  2. Hi Stanislav,

    This framing protocol is years old.  It is unchanged from when we originally shipped Indigo in 2006 to maintain wire compatibility.

  3. Thank you for submitting this cool story – Trackback from DotNetShoutout

  4. It’s snowing again. Like every other time in Southern-most NJ (near Philly) if it accumulates more than an inch, I will be astonished. Very unlike where we used to live in New Hampshire, where for 2 years, they have at least weekly snow storms of 8 or

  5. geff zhang says:


Skip to main content