1 Windows Communication Foundation (Indigo): A Deep Dive Into Extending The Channel Layer Kenny...

24
1 Windows Communication Windows Communication Foundation (“Indigo”): A Foundation (“Indigo”): A Deep Dive Into Extending The Deep Dive Into Extending The Channel Layer Channel Layer Kenny Wolf, Software Development Kenny Wolf, Software Development Engineer Engineer Yasser Shohoud, Lead Program Yasser Shohoud, Lead Program Manager Manager COM424 COM424 Microsoft Corporation Microsoft Corporation

Transcript of 1 Windows Communication Foundation (Indigo): A Deep Dive Into Extending The Channel Layer Kenny...

Page 1: 1 Windows Communication Foundation (Indigo): A Deep Dive Into Extending The Channel Layer Kenny Wolf, Software Development Engineer Yasser Shohoud, Lead.

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

Page 2: 1 Windows Communication Foundation (Indigo): A Deep Dive Into Extending The Channel Layer Kenny Wolf, Software Development Engineer Yasser Shohoud, Lead.

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

Page 3: 1 Windows Communication Foundation (Indigo): A Deep Dive Into Extending The Channel Layer Kenny Wolf, Software Development Engineer Yasser Shohoud, Lead.

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();();

Page 4: 1 Windows Communication Foundation (Indigo): A Deep Dive Into Extending The Channel Layer Kenny Wolf, Software Development Engineer Yasser Shohoud, Lead.

4

Channel TypesChannel Types

Protocol Protocol Channel(s)Channel(s)

Transport Transport ChannelChannel

ProxyProxy DispatchDispatcherer

Protocol Protocol Channel(s)Channel(s)

Transport Transport ChannelChannel

Page 5: 1 Windows Communication Foundation (Indigo): A Deep Dive Into Extending The Channel Layer Kenny Wolf, Software Development Engineer Yasser Shohoud, Lead.

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

Page 6: 1 Windows Communication Foundation (Indigo): A Deep Dive Into Extending The Channel Layer Kenny Wolf, Software Development Engineer Yasser Shohoud, Lead.

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

Page 7: 1 Windows Communication Foundation (Indigo): A Deep Dive Into Extending The Channel Layer Kenny Wolf, Software Development Engineer Yasser Shohoud, Lead.

7

Channel ShapesChannel Shapes

IOutputChannIOutputChannelel

IInputChannelIInputChannel

IRequestChannIRequestChannelel

IReplyChanneIReplyChannell

IDuplexChannIDuplexChannelel

IDuplexChannIDuplexChannelel

Page 8: 1 Windows Communication Foundation (Indigo): A Deep Dive Into Extending The Channel Layer Kenny Wolf, Software Development Engineer Yasser Shohoud, Lead.

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

Page 9: 1 Windows Communication Foundation (Indigo): A Deep Dive Into Extending The Channel Layer Kenny Wolf, Software Development Engineer Yasser Shohoud, Lead.

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))

Page 10: 1 Windows Communication Foundation (Indigo): A Deep Dive Into Extending The Channel Layer Kenny Wolf, Software Development Engineer Yasser Shohoud, Lead.

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)

Page 11: 1 Windows Communication Foundation (Indigo): A Deep Dive Into Extending The Channel Layer Kenny Wolf, Software Development Engineer Yasser Shohoud, Lead.

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

Page 12: 1 Windows Communication Foundation (Indigo): A Deep Dive Into Extending The Channel Layer Kenny Wolf, Software Development Engineer Yasser Shohoud, Lead.

12

Building a TCP TransportBuilding a TCP Transport

Page 13: 1 Windows Communication Foundation (Indigo): A Deep Dive Into Extending The Channel Layer Kenny Wolf, Software Development Engineer Yasser Shohoud, Lead.

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

Page 14: 1 Windows Communication Foundation (Indigo): A Deep Dive Into Extending The Channel Layer Kenny Wolf, Software Development Engineer Yasser Shohoud, Lead.

14

What We Will Show YouWhat We Will Show You

Page 15: 1 Windows Communication Foundation (Indigo): A Deep Dive Into Extending The Channel Layer Kenny Wolf, Software Development Engineer Yasser Shohoud, Lead.

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

Page 16: 1 Windows Communication Foundation (Indigo): A Deep Dive Into Extending The Channel Layer Kenny Wolf, Software Development Engineer Yasser Shohoud, Lead.

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

Page 17: 1 Windows Communication Foundation (Indigo): A Deep Dive Into Extending The Channel Layer Kenny Wolf, Software Development Engineer Yasser Shohoud, Lead.

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

Page 18: 1 Windows Communication Foundation (Indigo): A Deep Dive Into Extending The Channel Layer Kenny Wolf, Software Development Engineer Yasser Shohoud, Lead.

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

Page 19: 1 Windows Communication Foundation (Indigo): A Deep Dive Into Extending The Channel Layer Kenny Wolf, Software Development Engineer Yasser Shohoud, Lead.

19

Configuring ChannelsConfiguring ChannelsBinding Element ConfigurationBinding Element Configuration

ChunkingBindingElementChunkingBindingElementPropertiesProperties

Chunking Configuration Section

.config.config

App CodeApp Code

WS-PolicyWS-Policy

Policy Import

Page 20: 1 Windows Communication Foundation (Indigo): A Deep Dive Into Extending The Channel Layer Kenny Wolf, Software Development Engineer Yasser Shohoud, Lead.

20

Configuring ChannelsConfiguring ChannelsCustom BehaviorsCustom Behaviors

Custom Behavior

BindingParameters

BindingElement

ChannelFactory ChannelListener

Page 21: 1 Windows Communication Foundation (Indigo): A Deep Dive Into Extending The Channel Layer Kenny Wolf, Software Development Engineer Yasser Shohoud, Lead.

21

Using The Chunking Using The Chunking ChannelChannel

Page 22: 1 Windows Communication Foundation (Indigo): A Deep Dive Into Extending The Channel Layer Kenny Wolf, Software Development Engineer Yasser Shohoud, Lead.

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!

Page 23: 1 Windows Communication Foundation (Indigo): A Deep Dive Into Extending The Channel Layer Kenny Wolf, Software Development Engineer Yasser Shohoud, Lead.

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/

Page 24: 1 Windows Communication Foundation (Indigo): A Deep Dive Into Extending The Channel Layer Kenny Wolf, Software Development Engineer Yasser Shohoud, Lead.

24

© 2005 Microsoft Corporation. All rights reserved.This presentation is for informational purposes only. Microsoft makes no warranties, express or implied, in this summary.