Partager via


Creating Channels for Talking

When we last left the IChannel interface, there was a brief introduction of the concept of a channel manager.  A channel manager creates channels either for the client or server.  For those of you familiar with BSD sockets, we have the IChannelListener interface for producing channels that passively open and the IChanelFactory interface for producing channels that actively open.  For those of you not familiar with BSD sockets, it would be good to learn more about them because WCF mimics socket behavior in a lot of respects, but a channel listener produces channels that wait for a connection to occur and a channel factory produces channels that go out and create connections.  Both of these interfaces derive from the base interface, IChannelManager.

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

Let's start by looking at the easier of the two sides, the client.  On the client side, when you create a channel, you want to go out and establish a connection with some existing server.  You have to know where and how you're connecting, and this is only a limited time offer to make a connection.  If the server doesn't respond for some reason, then you want to just give up and return an error.  This makes the IChannelFactory case very simple because the only behavior we need is to be able to go off and create a connection.  Here are the two interfaces to describe that behavior.  Yes, there are two interfaces for just one concept because of reasons you probably don't care about most of the time.

 public interface IChannelFactory : IChannelManager, ICommunicationObject, IDisposable
{
}

public interface IChannelFactory<TChannel> : IChannelFactory
{
   TChannel CreateChannel(EndpointAddress to);
   TChannel CreateChannel(EndpointAddress to, Uri via);
}

The generic version is the one you want so pretend like that's all that exists if you can to make your life simpler.

As you can see, there's not a lot of conceptual overhead in creating a channel.  You always have to provide a destination address and you're given the option of providing a via.  Jump back to this quick description of the via for a refresher if you're unsure why you need both of these methods.  Note that all this is doing is creating your channel.  The actual act of opening the channel or sending data is all done through the IChannel interface.

Tomorrow, we'll look at IChannelListener, which is the twin to IChannelFactory.

Next time: Creating Channels for Listening

Comments

  • Anonymous
    March 21, 2006
    The final player in the drama between IRequestChannel and IReplyChannel is the link connecting requests...
  • Anonymous
    March 23, 2006
    Continuing from yesterday's article about IChannelFactory, today we're looking at the server side of...
  • Anonymous
    April 07, 2006
    After seeing the ChannelBase class yesterday for implementing a channel, today's post is about the base...