1
Windows Communication Windows Communication Foundation (“Indigo”): A Deep Foundation (“Indigo”): A Deep Dive Into Extending The Channel Dive Into Extending The Channel Layer Layer
Kenny Wolf, Software Development Kenny Wolf, Software Development EngineerEngineerYasser Shohoud, Lead Program ManagerYasser Shohoud, Lead Program ManagerCOM424COM424Microsoft CorporationMicrosoft Corporation
2
What’s in it for you?What’s in it for you?
Enable new transports (e.g. SMTP, Enable new transports (e.g. SMTP, UDP) UDP)
Integrate with other systems (e.g. Integrate with other systems (e.g. Java RMI) Java RMI)
Implement custom infrastructure Implement custom infrastructure protocolsprotocolsChannel extensibility is an Channel extensibility is an opportunity for component opportunity for component
vendorsvendors
3
Endpoints and ChannelsEndpoints and Channels
ServiceHost host = new ServiceHost(typeof(MyService));ServiceHost host = new ServiceHost(typeof(MyService));
Uri Uri addressaddress = new Uri(“net.tcp://kennyw2/Service/endpoint”); = new Uri(“net.tcp://kennyw2/Service/endpoint”);
Binding Binding bindingbinding = new NetTcpBinding(); = new NetTcpBinding();
Type Type contractcontract = typeof(IMyContract); = typeof(IMyContract);
host.AddEndpoint(address, binding, contract);host.AddEndpoint(address, binding, contract);
host.host.OpenOpen();();
4
Channel TypesChannel Types
Protocol Protocol Channel(s)Channel(s)
Transport Transport ChannelChannel
ProxyProxy DispatchDispatcherer
Protocol Protocol Channel(s)Channel(s)
Transport Transport ChannelChannel
5
Layered ExtensibilityLayered Extensibility
Protocol Protocol Channel(s)Channel(s)
Transport Transport ChannelChannel
ProxyProxy DispatchDispatcherer
Service Model ExtensibilityService Model Extensibility(local only)(local only)
Channel ExtensibilityChannel Extensibility(affects the wire)(affects the wire)
Protocol Protocol Channel(s)Channel(s)
Transport Transport ChannelChannel
6
OutlineOutline
Writing a TCP transportWriting a TCP transport
Writing a chunking protocol channelWriting a chunking protocol channel
Wrap up and Q&AWrap up and Q&A
7
Channel ShapesChannel Shapes
IOutputChannIOutputChannelel
IInputChannelIInputChannel
IRequestChannIRequestChannelel
IReplyChanneIReplyChannell
IDuplexChannIDuplexChannelel
IDuplexChannIDuplexChannelel
8
{0x08, 0xAF, 0x6D, 0xBE, 0xEF, ...}{0x08, 0xAF, 0x6D, 0xBE, 0xEF, ...}<Envelope><Body>...</Envelope><Envelope><Body>...</Envelope>
Unit of Data TransferredUnit of Data TransferredException contractException contract
Sockets vs. Channels Sockets vs. Channels (Client)(Client)
ClientClient ServiceService
SocketSocket ChannelChannel
new Socket();new Socket();socket.Connect(socket.Connect(IP, portIP, port))
CreateChannel(CreateChannel(UriUri););channel.Open()channel.Open()
socket.Send(socket.Send(byte[]byte[])) channel.Send(channel.Send(MessageMessage))
Throws Throws SocketExceptionSocketException
Throws Throws CommunicationExceptionCommunicationExceptionoror TimeoutException TimeoutException
(172.30.16.60, 808)(172.30.16.60, 808)
AddressingAddressing
my.tcpmy.tcp://kennyw2:808/myService/://kennyw2:808/myService/
socket.Close()socket.Close() channel.Close()channel.Close()
ShutdownShutdown
9
MessageEncoderMessageEncoderText, Binary, and MTOM ship with Text, Binary, and MTOM ship with “Indigo”“Indigo”
BufferManagerBufferManager
Proper tuning can yield large (Proper tuning can yield large (>10%>10%) ) performance increasesperformance increases
ArraySegment<byte> WriteMessage(Message, maxSize, ArraySegment<byte> WriteMessage(Message, maxSize, BufferManagerBufferManager))Message ReadMessage(ArraySegment<byte>, Message ReadMessage(ArraySegment<byte>, BufferManagerBufferManager))
Unit of Data TransferUnit of Data TransferMessage Message Bytes Bytes
void WriteMessage(Message message, Stream stream)void WriteMessage(Message message, Stream stream)Message ReadMessage(Stream stream, int maxSizeOfHeaders)Message ReadMessage(Stream stream, int maxSizeOfHeaders)
BufferManager.CreateBufferManager(long BufferManager.CreateBufferManager(long maxBufferPoolSizemaxBufferPoolSize,int ,int maxSizemaxSize))
10
Unit of Data TransferUnit of Data TransferFraming Message BytesFraming Message Bytes
Need to encapsulate Need to encapsulate certain information certain information outside of the SOAP outside of the SOAP messagemessage
Byte Length of DataByte Length of Data
Content Type & Uri for Content Type & Uri for ChannelChannel
Method: 4 byte size, then Method: 4 byte size, then datadata
CreateChannel(“my.tcp://kennyw2/a/”)CreateChannel(“my.tcp://kennyw2/a/”)
my.tcp://kennyw2/a/my.tcp://kennyw2/a/191938638688text/xmltext/xml
channel.Open()channel.Open()channel.Send(message)channel.Send(message)
11
AddressingAddressingShutdownShutdown
Sockets vs. Channels Sockets vs. Channels (Service)(Service)
ClientClient ServiceService
SocketSocket ChannelChannel
new Socket();new Socket();listenSocket.Bind(listenSocket.Bind(IP, portIP, port););listenSocket.Listen();listenSocket.Listen();
BuildChannelListener<T>(BuildChannelListener<T>(UriUri););listener.Open();listener.Open();
socket.Receive(socket.Receive(byte[]byte[])) Message Message = channel.Receive()= channel.Receive()
IChannel IChannel = listener.AcceptChannel();= listener.AcceptChannel();Socket Socket = listenSocket.Accept()= listenSocket.Accept()
socket.Close()socket.Close() channel.Close()channel.Close()
Unit of Data TransferredUnit of Data TransferredAcceptAccept
12
Building a TCP TransportBuilding a TCP Transport
13
OutlineOutline
Writing a TCP transportWriting a TCP transport
Writing a chunking protocol channelWriting a chunking protocol channel
Wrap up and Q&AWrap up and Q&A
14
What We Will Show YouWhat We Will Show You
15
Managing Inner Channel Managing Inner Channel StateState
Open
Close
Abort
• Open inner channel
• Wait for pending sends, if any• Drain session, if applicable • Close inner channel
• Abort inner channel
16
Handling Inner Channel Handling Inner Channel EventsEvents
Opened
Opening
Closing
Useful for reacting to state transitions when your code is not driving the channel
When inner channel faults, your channel should recover or fault
Closed
Faulted
17
MessageMessage
Message is the unit of I/O in IndigoMessage is the unit of I/O in IndigoBased on XML InfoSetBased on XML InfoSet
Consists of headers and bodyConsists of headers and body
Message HeadersMessage HeadersBuffered, random access collectionBuffered, random access collection
Used to implement infrastructure Used to implement infrastructure protocolsprotocols
Message BodyMessage BodyForward-only cursorForward-only cursor
Used to carry application dataUsed to carry application data
18
Working With MessageWorking With Message
Reading body contentReading body content
Creating messages using BodyWriterCreating messages using BodyWriter
Reading and writing headersReading and writing headers
Creating messages using Creating messages using XmlDictionaryReaderXmlDictionaryReader
Custom messagesCustom messages
19
Configuring ChannelsConfiguring ChannelsBinding Element ConfigurationBinding Element Configuration
ChunkingBindingElementChunkingBindingElementPropertiesProperties
Chunking Configuration Section
.config.config
App CodeApp Code
WS-PolicyWS-Policy
Policy Import
20
Configuring ChannelsConfiguring ChannelsCustom BehaviorsCustom Behaviors
Custom Behavior
BindingParameters
BindingElement
ChannelFactory ChannelListener
21
Using The Chunking Using The Chunking ChannelChannel
22
Key Take AwaysKey Take Aways
Write custom channels when you Write custom channels when you need toneed to
Change what goes on the Change what goes on the wirewire
IntegrateIntegrate with arbitrary systems with arbitrary systems
Enable new Enable new transportstransports
Channel extensibility is an Channel extensibility is an opportunityopportunity for component vendors for component vendors
Please fill out the evaluationPlease fill out the evaluationWe want to know what you think!We want to know what you think!
23
Community ResourcesCommunity ResourcesAt PDCAt PDC
COM429COM429: A Deep Dive into Extending the Service : A Deep Dive into Extending the Service Model Layer Model Layer (Fri 10:30am)(Fri 10:30am)COM413COM413: IIS and Windows Communication Foundation : IIS and Windows Communication Foundation (“Indigo”): Hosting Services (Fri 1pm)(“Indigo”): Hosting Services (Fri 1pm)Labs: Labs: COMHOL29COMHOL29Ask The Experts table: Ask The Experts table: ExtendingExtending WCFWCFCOM Track lounge: We’ll be there COM Track lounge: We’ll be there Thu 5-6pm, Fri Thu 5-6pm, Fri 8:30-noon8:30-noon
After PDCAfter PDCIf you missed this related session, watch it on the DVDIf you missed this related session, watch it on the DVD
COM424: WCF: A Deep Dive into Extending the Channel COM424: WCF: A Deep Dive into Extending the Channel LayerLayer
MSDN dev center: MSDN dev center: http://msdn.microsoft.com/webservices/http://msdn.microsoft.com/webservices/MSDN Forum: MSDN Forum: Windows Communication Foundation ("Indigo")Windows Communication Foundation ("Indigo")http://www.kennyw.com/indigo/http://www.kennyw.com/indigo/http://blogs.msdn.com/yassers/http://blogs.msdn.com/yassers/ Channel 9 tag: Channel 9 tag: http://channel9.msdn.com/tags/Indigo/http://channel9.msdn.com/tags/Indigo/
24
© 2005 Microsoft Corporation. All rights reserved.This presentation is for informational purposes only. Microsoft makes no warranties, express or implied, in this summary.