Stream Upgrades, Part 1

The next several posts are about the stream upgrade model for modifying the byte stream output of a transport. I'll use these posts to cover the basic elements of the stream upgrade model, take a break for a while to talk about some other topics, and later have a sample that shows building a stream upgrade from scratch.

A stream upgrade takes the output from message serialization and replaces that byte stream with another byte stream. Stream upgrades are represented in the channel stack by a binding element that doesn't actually create a channel. It is legal to have more than one stream upgrade in the channel stack and active at the same time. These stream upgrades chain sequentially so that the stream output of one is passed as the stream input to the next one. Our primary use of stream upgrades is to provide transport security by replacing the unencrypted stream with an encrypted stream. You could also use stream upgrades for tasks such as compression, character re-encoding, or byte reordering.

public abstract class StreamUpgradeBindingElement : BindingElement
protected StreamUpgradeBindingElement();
protected StreamUpgradeBindingElement(StreamUpgradeBindingElement elementToBeCloned);

public abstract StreamUpgradeProvider BuildClientStreamUpgradeProvider(BindingContext context);
public abstract StreamUpgradeProvider BuildServerStreamUpgradeProvider(BindingContext context);

Building a client or server StreamUpgradeProvider is very similar to constructing a ChannelFactory or ChannelListener for a particular channel. The StreamUpgradeProvider class will be the topic of tomorrow's post.

Since there's no channel corresponding to the stream upgrade, the transport is the part of the channel stack that's responsible for actually creating and using the stream upgrade. This means that stream upgrades are only going to be supported by certain transports. Our named pipe and TCP transports, the connection-oriented transports, both support stream upgrades. These transports provide connections that flow undelimited streams of bytes, meaning that they mesh well with the stream upgrade model. Our HTTP transport does not support stream upgrades.

Applying a stream upgrade to a connection is optional. The stream upgrades included in the channel stack represent the maximum collection of upgrades that can be used with a connection. The client and server sides have to negotiate and agree on the collection of stream upgrades that will be used for a particular collection. The process for negotiation is covered in a later post.

Next time: Stream Upgrades, Part 2

Comments (7)

  1. WCF allows you to customize the collection of message headers sent with a request, including defining…

  2. Today’s the final part of the series on the stream upgrade model (StreamUpgradeBindingElement and StreamUpgradeProvider…

  3. The mission for the next five days is to build and demonstrate an implementation of a stream upgrade….

  4. Building a stream upgrade for ROT 128 starts with creating a binding element to put in the channel stack….

  5. Today’s the final part of the series on the stream upgrade model ( StreamUpgradeBindingElement and StreamUpgradeProvider

  6. The stream upgrade model consists of four abstract base classes. We looked at the StreamUpgradeBindingElement

Skip to main content