330 likes | 519 Views
WCF (Indigo): Under the Hood of the Channel Layer. Steve Swartz COM416 Architect Microsoft Corporation. C. C. C. B. B. B. A. A. A. From the Outside. Client. Service. Bv. Bv. Message. Bv. Bv. Address. Binding. Contract. (Where). (How). (What). C. C. B. B. A. A.
E N D
WCF (Indigo): Under the Hood of the Channel Layer Steve Swartz COM416 Architect Microsoft Corporation
C C C B B B A A A From the Outside Client Service Bv Bv Message Bv Bv Address Binding Contract (Where) (How) (What)
C C B B A A From the Inside Service Bv Bv
Positioning This Talk • This Talk • How Does the Channel Layer Work? • Why Do You Care? • Other Talks • How Does the ServiceModel Work? • COM417: Thursday, 10:00am • How Do You Build XML Messaging Apps? • COM326: Thursday, 5:15pm • How Do You Build Channels? • COM424: Thursday, 3:45pm • How Do You Hook Channels Into WebHost? • COM413: Friday, 1:00pm
Big Ideas • Bindings: How You Use The Channel Layer • Bindings Are Easy & Extensible • Channels: How Messages Are Exchanged • Channels have Shape, Capabilities, Stacks • Factories: How Channels Are Created
Factory Factory Factory Listener Listener Listener Channel Channel Channel Channel Channel Channel The Talk-In-A-Slide Binding Binding Factory Listener CreateChannel<T>() AcceptChannel() Channel Channel Send() Receive() Message
Factory Factory Factory Listener Listener Listener Channel Channel Channel Channel Channel Channel Agenda: Message Binding Binding Factory Listener CreateChannel<T>() AcceptChannel() Channel Channel Send() Receive() Message
Message: The Basics • CLR Representation of SOAP Infoset • Supports SOAP 1.1 / SOAP 1.2 • Encoding-Agnostic • Stream-Oriented public abstract class Message : IDisposable { public abstract MessageHeaders Headers { get; } public abstract MessageProperties Properties { get; } public abstract MessageVersion Version { get; } public T GetBody<T>() { } static public Message CreateMessage(...) { } public void WriteMessage(XmlWriter writer) { } }
Message: Constructors • Select Action • Select Message Version • Select Formatter • Body as Object, XMLReader • Special Support for Faults, Replies
Factory Factory Factory Listener Listener Listener Channel Channel Channel Channel Channel Channel Agenda: Bindings Binding Binding Factory Listener CreateChannel<T>() AcceptChannel() Channel Channel Send() Receive() Message
C C C B B B A A A Bindings: What Are They? Client Service Message Address Binding Contract (Where) (How) (What)
Bindings: Out of the Box T = Transport Security | S = WS-Security | O = One-Way Only
Bindings: Scenarios • Shipping Channels • Change defaults • Change options • Change set of channels used • Future Channels • Change versions, functionality • Preserve app code • Custom Channels • Binding benefits for any channel
Binding: Object Model public abstract class Binding : IDefaultCommunicationTimeouts { protected Binding() { } public abstract string Scheme { get; set{} } public TimeSpan OpenTimeout { get; set{} } public TimeSpan SendTimeout { get; set{} } public TimeSpan ReceiveTimeout { get; set{} } public TimeSpan CloseTimeout { get; set{} } public virtual IChannelFactory<TChannel> BuildChannelFactory<TChannel>(BindingParameterCollection p) {} public virtual IChannelListener<TChannel> BuildChannelListener<TChannel>(BindingParameterCollection p) {} }
Bindings: Build Your Own • Subclass Binding • An (Internal) Binding Element Collection • Completely Defines Binding, Channel Stack • A Constructor • Loads and Initializes B.E. Collection • A Public API • Simplifies Working With B.E. Collection
Binding: Binding Elements public abstract class BindingElement { protected BindingElement() { } public virtual IChannelFactory<TChannel> BuildChannelFactory<TChannel>(ChannelBuildContext context) {} public virtual IChannelListener<TChannel> BuildChannelListener<TChannel>(ChannelBuildContext context) {} } public class ChannelBuildContext { public ChannelBuildContext() {} public BindingElementCollection UnhandledBindingElements { get; } public BindingParameterCollection BindingParameters { get; } public IChannelFactory<TChan> BuildInnerChannelFactory<TChan>() {} public IChannelListener<TChan> BuildInnerChannelListener<TChan>(){} BindingElement RemoveNextElement(){} }
Bindings: Building Factories • Call “Build()” on First Binding Element • It Builds Its Factory • It Optionally Consumes Binding Elements • It Optionally Consumes Binding Parameters • It Calls “BuildInner()” on BuildContext • It Wires Inner Factory to Itself • It Returns
Factory Factory Factory Listener Listener Listener Channel Channel Channel Channel Channel Channel Agenda: Factories Binding Binding Factory Listener CreateChannel<T>() AcceptChannel() Channel Channel Send() Receive() Message
Factories: In Perspective • Apps use Channels • Factories Create Channels • Factories Share Resources • Per Process • Per Machine Channel Factory Process Manager MachineManager
ICommunicationObject • Implemented by all channels, factories public interface ICommunicationObject : IDisposable { // Created, Opening, Opened, Closing, Closed, Faulted CommunicationState State { get; } event EventHandler Closed; event EventHandler Closing; event EventHandler Faulted; event EventHandler Opened; event EventHandler Opening; // Async Calls Available, Too void Open(); void Close(); void Abort(); }
IChannelManager • Implemented by all channels, factories public interface IChannelManager : ICommunicationObject { MessageVersion MessageVersion { get; } string Scheme { get; } ReadOnlyCollection<IChannel> GetChannels(); T GetProperty<T>() where T : class; }
Factories: The Client • Clients Initiate Connections • One contract, one binding, many addresses • Async methods available public interface IChannelFactory<TChannel> : IChannelFactory { TChannel CreateChannel(string address); TChannel CreateChannel(Uri address); TChannel CreateChannel(EndpointAddress to); } public interface IChannelFactory : IChannelManager { }
Factories: The Service • Services Passively Wait For Connectinons • One address, one binding, many contracts • Async methods available public interface IChannelListener<TChannel> : IChannelListener { void SetUri( /* … */ ); bool WaitForChannel(TimeSpan timeout); TChannel AcceptChannel(); TChannel AcceptChannel(TimeSpan timeout); } public interface IChannelListener : IChannelManager { }
Factory Factory Factory Listener Listener Listener Channel Channel Channel Channel Channel Channel Agenda: Channels Binding Binding Factory Listener CreateChannel<T>() AcceptChannel() Channel Channel Send() Receive() Message
Channels: Three Shapes public interface IOutputChannel : IChannel { void Send(Message message); } public interface IInputChannel : IChannel { Message Receive(); } public interface IDuplexChannel : IInputChannel, IOutputChannel { } public interface IRequestChannel : IChannel { Message Request(Message message); } public interface IReplyChannel : IChannel { IRequestContext ReceiveRequest(); } public interface IRequestContext : IDisposable { Message RequestMessage { get; } void Reply(Message message); }
Channels: Sessions public interface ISession { string Id { get; } } public interface ISessionChannel<SessionType> where SessionType : ISession { SessionType Session { get; } } public interface IInputSession : ISession { } public interface IInputSessionChannel : IInputChannel, ISessionChannel<IInputSession> { }
Channel Families: Transports Channel Channel Channel Transport
Channel Families: Encoders Channel Channel Channel Channel Encoder
Channel Channel Channel Families: Dual Channel DualChannel
Channel Families: Protocols ProtocolChannel EP EP ProtocolChannel TransportChannel TransportChannel M M Message M M
In Summary • Bindings: How You Use The Channel Layer • Bindings Are Easy & Also Extensible • Channels: How Messages Are Exchanged • Channels have Shape, Capabilities, Stacks • Factories: How Channels Are Created
Community Resources • At PDC • For more information, go see • Service Model Internals: COM417, Thursday, 10:00am • XML Messaging: COM326, Thursday, 5:15pm • Building Channels: COM424, Thursday, 3:45pm • WebHost Integration: COM413, Friday, 1:00pm • Ask The Experts table: WCF Internals • I’ll be at COM Track lounge: Thu 3:30-6:30pm, Fri 8:30-11am • After PDC • If you miss some of these sessions, watch the DVD! • MSDN dev center • The WCF newsgroup • Channel 9 tag
© 2005 Microsoft Corporation. All rights reserved. This presentation is for informational purposes only. Microsoft makes no warranties, express or implied, in this summary.