다음을 통해 공유


And Starring IChannel

I've been giving a tour around the WCF channel stack without ever really explaining what channels are.  Today, tomorrow, and for even more days yet to come, we'll spelunk into the heart of channels.

A channel is simply a conduit through which messages flow.  Every message going into or out of a WCF application passes through a channel.  Along the way, channels can do all kinds of exciting things to your message in order to provide services.  You can write channels that observe messages passing through and log information.  You can write channels that apply policy to decide what messages can go through.  You can write channels that fold, spindle, and mutilate messages if you want.  You can do pretty much anything with a channel, and then you can package up an interesting collection of channels into a binding that describes a sequence of message transforming operations.

All of this power comes from this one little interface:

 public interface IChannel : ICommunicationObject
{
   IChannelManager Manager { get; }
   T GetProperty<T>() where T : class;
}

How uninteresting!  Where are all the methods for sending and receiving data?  As we'll see tomorrow, channels come in a variety of shapes that describe their message passing modes.  It's only once you select a particular shape for a channel that you have semantics like input and output.  However, we do have a channel manager property that sounds possibly interesting.

 public interface IChannelManager : ICommunicationObject
{
   MessageVersion MessageVersion { get; } 
   string Scheme { get; }
   T GetProperty<T>() where T : class;
}

Hmm, not much there either.  The channel manager is what creates channels, but just like for plain old sockets, there's different behavior depending on whether you're creating client or server channels.  On the base interface is just a few methods for describing what goes through the channel.  We'll come back to channel managers in a few days after looking at some of the channel shapes.

As a side note, both the channel and channel manager have the same mysterious GetProperty method that we saw on the binding and binding element.  Let's say that one of your channels is interested in knowing whether something in the channel stack supports the IFooable interface.  IFooable may mean something to the channel for security, management, policy, or things like that.  With this giant channel stack, and possibly channels internally delegating to other channels, how are you ever going to find out whether a message will be IFooable'd along the way?  Well, you'll simply call GetProperty with IFooable in place of T!  The role of GetProperty is to basically search for the needle in your channel stack.

Next time: Windows Communication Foundation Channel Shapes

Comments

  • Anonymous
    March 06, 2006
    Back to the subject of bindings, a binding is what ties together the description of a channel stack.&amp;nbsp;...
  • Anonymous
    March 14, 2006
    Last week I introduced the different kinds of channel shapes that are available with WCF.&amp;nbsp; This...
  • Anonymous
    March 22, 2006
    When we last left the IChannel interface, there was a brief introduction of the concept of a channel...
  • Anonymous
    April 06, 2006
    After a bit of a diversion, let's spend some time again looking at the parts necessary to build a custom...