240 likes | 424 Views
Windows Communication Foundation (“Indigo”): A Deep Dive Into Extending The Channel Layer . Kenny Wolf, Software Development Engineer Yasser Shohoud, Lead Program Manager COM424 Microsoft Corporation. What’s in it for you?. Enable new transports (e.g. SMTP, UDP)
E N D
Windows Communication Foundation (“Indigo”): A Deep Dive Into Extending The Channel Layer Kenny Wolf, Software Development Engineer Yasser Shohoud, Lead Program Manager COM424 Microsoft Corporation
What’s in it for you? • Enable new transports (e.g. SMTP, UDP) • Integrate with other systems (e.g. Java RMI) • Implement custom infrastructure protocols Channel extensibility is an opportunity for component vendors
Endpoints and Channels ServiceHost host = new ServiceHost(typeof(MyService)); Uri address = new Uri(“net.tcp://kennyw2/Service/endpoint”); Binding binding = new NetTcpBinding(); Type contract = typeof(IMyContract); host.AddEndpoint(address, binding, contract); host.Open();
Proxy Dispatcher Protocol Channel(s) Transport Channel Protocol Channel(s) Transport Channel Channel Types
Proxy Dispatcher Protocol Channel(s) Transport Channel Protocol Channel(s) Transport Channel Layered Extensibility Service Model Extensibility (local only) Channel Extensibility (affects the wire)
Outline • Writing a TCP transport • Writing a chunking protocol channel • Wrap up and Q&A
IOutputChannel IInputChannel IRequestChannel IReplyChannel IDuplexChannel IDuplexChannel Channel Shapes
Client Service Sockets vs. Channels (Client) Channel Socket CreateChannel(Uri); channel.Open() new Socket(); socket.Connect(IP, port) channel.Send(Message) socket.Send(byte[]) Throws CommunicationException or TimeoutException Throws SocketException socket.Close() channel.Close() Exception contract Unit of Data Transferred Shutdown Addressing <Envelope><Body>...</Envelope> my.tcp://kennyw2:808/myService/ {0x08, 0xAF, 0x6D, 0xBE, 0xEF, ...} (172.30.16.60, 808)
Unit of Data TransferMessage Bytes • MessageEncoder • Text, Binary, and MTOM ship with “Indigo” • BufferManager • Proper tuning can yield large (>10%) performance increases ArraySegment<byte> WriteMessage(Message, maxSize, BufferManager) Message ReadMessage(ArraySegment<byte>, BufferManager) void WriteMessage(Message message, Stream stream) Message ReadMessage(Stream stream, int maxSizeOfHeaders) BufferManager.CreateBufferManager(long maxBufferPoolSize,int maxSize)
Unit of Data TransferFraming Message Bytes • Need to encapsulate certain information outside of the SOAP message • Byte Length of Data • Content Type & Uri for Channel • Method: 4 byte size, then data 19 text/xml my.tcp://kennyw2/a/ 386 8 channel.Open() CreateChannel(“my.tcp://kennyw2/a/”) channel.Send(message)
Client Service Sockets vs. Channels (Service) Channel Socket new Socket(); listenSocket.Bind(IP, port); listenSocket.Listen(); BuildChannelListener<T>(Uri); listener.Open(); IChannel = listener.AcceptChannel(); Socket = listenSocket.Accept() socket.Receive(byte[]) Message = channel.Receive() socket.Close() channel.Close() Unit of Data Transferred Shutdown Accept Addressing
Outline • Writing a TCP transport • Writing a chunking protocol channel • Wrap up and Q&A
Managing Inner Channel State Open • Open inner channel • Wait for pending sends, if any • Drain session, if applicable • Close inner channel Close Abort • Abort inner channel
Handling Inner Channel Events Opened Opening Useful for reacting to state transitions when your code is not driving the channel Closing Closed Faulted When inner channel faults, your channel should recover or fault
Message • Message is the unit of I/O in Indigo • Based on XML InfoSet • Consists of headers and body • Message Headers • Buffered, random access collection • Used to implement infrastructure protocols • Message Body • Forward-only cursor • Used to carry application data
Working With Message • Reading body content • Creating messages using BodyWriter • Reading and writing headers • Creating messages using XmlDictionaryReader • Custom messages
App Code WS-Policy Configuring ChannelsBinding Element Configuration ChunkingBindingElement Properties Chunking Configuration Section Policy Import .config
Custom Behavior BindingParameters BindingElement ChannelFactory ChannelListener Configuring ChannelsCustom Behaviors
Key Take Aways • Write custom channels when you need to • Change what goes on the wire • Integrate with arbitrary systems • Enable new transports • Channel extensibility is an opportunity for component vendors Please fill out the evaluation We want to know what you think!
Community Resources • At PDC • COM429: A Deep Dive into Extending the Service Model Layer (Fri 10:30am) • COM413: IIS and Windows Communication Foundation (“Indigo”): Hosting Services (Fri 1pm) • Labs: COMHOL29 • Ask The Experts table: ExtendingWCF • COM Track lounge: We’ll be there Thu 5-6pm, Fri 8:30-noon • After PDC • If you missed this related session, watch it on the DVD • COM424: WCF: A Deep Dive into Extending the Channel Layer • MSDN dev center: http://msdn.microsoft.com/webservices/ • MSDN Forum: Windows Communication Foundation ("Indigo") • http://www.kennyw.com/indigo/ • http://blogs.msdn.com/yassers/ • Channel 9 tag: http://channel9.msdn.com/tags/Indigo/
© 2005 Microsoft Corporation. All rights reserved. This presentation is for informational purposes only. Microsoft makes no warranties, express or implied, in this summary.