Partager via


When to Write a Channel

Today's article is about the tension between two simple points.

-
Writing channels can generally be used to solve just about any problem in WCF

  • Writing channels is generally the most time-consuming way to solve a problem in WCF

The key inference that you should be taking away from this discussion follows pretty directly from these points.

Just because you can go out and solve your problem by writing a channel doesn't mean that writing a channel is the right answer to your problem.

How do you know if there's a more cost-effective solution to your problem than writing a channel? Well, that's always going to be a difficult question to answer because there are many very subtle points that cause solutions to explode in complexity. In contrast, channels have a very regular and ordered structure that makes it easy to reason about systems composed from channels (we'll be looking at this structure a lot more in the future). We can exploit the regularity of the channel model by identifying types of problems that work very naturally with channels and by identifying other types of problems that most likely have a better solution elsewhere. Think of this as a pocket-guide to helping you make the decision.

1.
Channels are the component in WCF that interfaces with the network. If you have to take some direct action on a network resource, either sending or receiving data, then you are typically talking about building or using a channel. 2. Channels are the component in WCF that establish a pattern of message exchange. When you're having a conversation, there are social rules that dictate when someone can start talking. Different social situations have different sets of rules. In WCF messaging, channels provide the equivalent of these rules of exchange. 3. Similarly, channels represent the social protocols for how to format ideas for exchange but say nothing about what ideas can be exchanged. 4. In the most basic messaging pipeline, there is a one-to-one correspondence between messages entering and leaving the pipeline. Many of the components of WCF follow this simple pipeline model but channels do not. Channels take an arbitrary number of input messages (even zero) and produce an arbitrary number of output messages (again, even zero). 5. Just because you have a message-processing system doesn't mean that you can't make method calls. For example, if all you want to do is execute some SQL query from within your service, then use ADO.NET. If you have built some predefined send and receive operations that just happen to have been implemented against a database, that's when you write a channel.

Next time: Protocol Channels

Comments

  • Anonymous
    February 20, 2007
    This is the start of a long series on channel development. Some of the material in the series is going

  • Anonymous
    February 21, 2007
    Architecture/SOA Blaine Wastell has posted that PAG planning an update of the Smart Client Software Factory

  • Anonymous
    March 13, 2007
    This pair of articles marks the checkpoint between the "big picture" introductory segments and the segments

  • Anonymous
    April 11, 2007
    Windows Communication Foundation (WCF) is Microsoft's unified programming model for building service-oriented

  • Anonymous
    December 03, 2008
    Architecture/SOA Blaine Wastell has posted that PAG planning an update of the Smart Client Software Factory to be released in late April of this year. They are encouraging feedback at http://www.codeplex.com/smartclient and enter critical items into the