Windows Communication Foundation (“Indigo”): A Deep Dive

Download Report

Transcript Windows Communication Foundation (“Indigo”): A Deep Dive

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
1
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
2
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();
3
Channel Types
Proxy
Dispatcher
Protocol
Channel(s)
Protocol
Channel(s)
Transport
Channel
Transport
Channel
4
Layered Extensibility
Service Model Extensibility
(local only)
Proxy
Dispatcher
Protocol
Channel(s)
Protocol
Channel(s)
Transport
Channel
Channel Extensibility
(affects the wire)
Transport
Channel
5
Outline
Writing a TCP transport
Writing a chunking protocol channel
Wrap up and Q&A
6
Channel Shapes
IOutputChannel
IInputChannel
IRequestChanne
l
IReplyChannel
IDuplexChanne
l
IDuplexChannel
7
Sockets vs. Channels (Client)
Socket
Channel
new Socket();
socket.Connect(IP, port)
CreateChannel(Uri);
channel.Open()
socket.Send(byte[])
channel.Send(Message)
Throws SocketException
Throws CommunicationException
or TimeoutException
channel.Close()
socket.Close()
Exception
contract
Unit
ofAddressing
Data
Transferred
Shutdown
Client
<Envelope><Body>...</Envelope>
my.tcp://kennyw2:808/myService/
{0x08,
0xAF, 0x6D,
0xBE, 0xEF, ...}
(172.30.16.60,
808)
Service
8
Unit of Data Transfer
Message  Bytes
MessageEncoder
Text, Binary, and MTOM ship with “Indigo”
ArraySegment<byte>
WriteMessage(Message,
maxSize,
BufferManager)
void WriteMessage(Message
message, Stream
stream)
Message
ReadMessage(ArraySegment<byte>,
BufferManager)
Message
ReadMessage(Stream stream, int
maxSizeOfHeaders)
BufferManager
BufferManager.CreateBufferManager(long maxBufferPoolSize,int maxSize)
Proper tuning can yield large (>10%)
performance increases
9
Unit of Data Transfer
Framing 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
text/xml
my.tcp://kennyw2/a/
19
386
8
channel.Open()
CreateChannel(“my.tcp://kennyw2/a/”)
channel.Send(message)
10
Sockets vs. Channels
(Service)
Channel
Socket
new Socket();
listenSocket.Bind(IP, port);
listenSocket.Listen();
BuildChannelListener<T>(Uri);
listener.Open();
Socket = listenSocket.Accept()
IChannel = listener.AcceptChannel();
socket.Receive(byte[])
Message = channel.Receive()
socket.Close()
channel.Close()
Unit ofAddressing
Data
Transferred
Shutdown
Accept
Client
Service
11
Building a TCP Transport
12
Outline
Writing a TCP transport
Writing a chunking protocol channel
Wrap up and Q&A
13
What We Will Show You
14
Managing Inner Channel State
Open
• Open inner channel
Close
• Wait for pending sends, if any
• Drain session, if applicable
• Close inner channel
Abort
• Abort inner channel
15
Handling Inner Channel Events
Opened
Opening
Closing
Useful for reacting to state
transitions when your code is
not driving the channel
Closed
Faulted
When inner channel faults, your
channel should recover or fault
16
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
17
Working With Message
Reading body content
Creating messages using BodyWriter
Reading and writing headers
Creating messages using
XmlDictionaryReader
Custom messages
18
Configuring Channels
Binding Element Configuration
ChunkingBindingElement
App Code
Properties
Chunking Configuration
Section
Policy Import
.config
WS-Policy
19
Configuring Channels
Custom Behaviors
Custom Behavior
BindingParameters
BindingElement
ChannelFactory
ChannelListener
20
Using The Chunking Channel
21
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!
22
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: Extending WCF
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/
23
© 2005 Microsoft Corporation. All rights reserved.
This presentation is for informational purposes only. Microsoft makes no warranties, express or implied, in this summary.
24