1 / 32

WCF Communication Patterns: More than Request-Reply

WCF Communication Patterns: More than Request-Reply. Christian Weyer thinktecture Co-Founder & Solution Architect http://www.thinktecture.com/staff/christian christian.weyer@thinktecture.com. WCF Communication Patterns: More than Request-Reply. Christian Weyer thinktecture

dai
Download Presentation

WCF Communication Patterns: More than Request-Reply

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. WCF Communication Patterns:More than Request-Reply Christian Weyer thinktecture Co-Founder & Solution Architect http://www.thinktecture.com/staff/christian christian.weyer@thinktecture.com

  2. WCF Communication Patterns:More than Request-Reply Christian Weyer thinktecture Co-Founder & Solution Architect http://www.thinktecture.com/staff/christian christian.weyer@thinktecture.com

  3. What To Expect • ABC 101 • Internals 101 • MEPs 101 • Contracts and MEPs • Bindings and MEPs • Real-World Check

  4. ABC 101

  5. WCF: Bird’s Eye View Client Service Endpoint Endpoint Endpoint Endpoint

  6. WCF: Address, Binding, Contract Client Service A B C A B C C B A A B C Address Where? Binding How? Contract What? Endpoint

  7. Internals 101

  8. WSDL Importer Service Model Layer Contract Contract WSDL Exporter Client Code parameters Service Type parameters Operation Invoker Dispatcher Runtime Parameter Inspector Parameter Inspector Client Runtime Message Formatter Message Formatter Operation Selector Message Inspector Message Inspector Channel Layer Channel Custom Channel Channel Custom Channel Channel Custom Channel Channel Custom Channel Transport Channel byte[] Transport Channel byte[] Encoder Encoder Custom Encoder Custom Encoder Custom Transport Custom Transport * Added by configuring the runtime with behaviors * Added by adding binding elements to the binding

  9. Layered Extensibility Client Runtime Dispatch Runtime Protocol Channel(s) Transport Channel Protocol Channel(s) Transport Channel Service Model Extensibility (local only) Channel Extensibility (affects the wire)

  10. MEPs 101

  11. Telephone or answering machine Synchronous vs. asynchronous execution Orthogonal to communication pattern Developers typically choose the way of least resistance Synchronous programming is what they are used to Threading, synchronization, callbacks et. al. are too cumbersome Real power is in decoupling systems Asynchronous communication in distributed solutions can solve a lot of issues – but can also introduce new ones

  12. Message-based Communication Messages travel between communication parties Messages can be grouped into different message exchange patterns (MEPs) MEPs can be implemented synchronously or asynchronously WCF supports different MEPs One-way Request-reply Duplex WCF MEPs implemented by different kinds of channels

  13. Channel Shapes IOutputChannel IInputChannel IRequestChannel IReplyChannel IDuplexChannel IDuplexChannel

  14. Channel Shaping Possible mismatch: Physical transport Logical message exchange patterns Channel shapes implemented in transport bindings Express support for MEPs WCF ServiceModel analyzes contract Which channel shapes will be supported? ServiceChannelFactory.BuildChannelFactory and DispatcherBuilder.GetSupportedChannelTypes have the details

  15. Contracts & MEPs

  16. [Contracts]Request-Reply Most commonly used MEP It is easy to use and looks natural R/R can be implemented in WCF by several approaches Parameter list DataContract MessageContract Message Mind the ‚public face‘ of contracts, i.e. the metadata

  17. [Contracts]One-Way O/W operations smell more feasible when decoupling is goal No return values, rather void Use IsOneWay property of OperationContract O/W operations can still block Not really fire-and-forget semantics

  18. [Contracts]Duplex Having peer communication parties Blurring the line between client and server Use CallbackContract property of ServiceContract Operations in contracts can be one-way, but need no to be If using non-one-way beware of threading issues

  19. [Contracts]Streaming Buffered communication can be very expensive with large data WCF offers streamed transfer Contract parameters must have certain shape Use Message, IXmlSerializable or System.IO.Stream or derivate as type Use MessageContract Headers will be buffered Body as System.IO.Stream will be streamed Only works with appropriate binding

  20. Bindings & MEPs

  21. WCF‘s Hidden Power

  22. [Bindings]Request-Reply Almost all out-of-the-box bindings support request-reply MSMQ-based bindings do not For all bindings and MEPs: Beware of default min/max values on binding elements for e.g. message sizes and buffers and timeouts Beware of possible throttles on service behavior

  23. [Bindings]One-Way All bindings support one-way operations Use OneWayBindingElement for custom bindings to shape channel Performs a message-level shape change Can take a IDuplexSessionChannel or a IRequestChannel and expose it as a IOutputChannel, or conversely it can take a IDuplexSessionChannel or a IReplyChannel and expose it as a IInputChannel

  24. [Bindings]Duplex Duplex out-of-the-box netTcp wsDualHttp netNamedPipe netPeerTcp Manual duplex session-less, e.g. <compositeDuplex /> <oneWay /> <binaryMessageEncoding /> <httpTransport />

  25. [Bindings]Streaming Enable streaming on the baked-in bindings All standard bindings besides MSMQ-based Enable streaming on the transport binding element, e.g. <httpTransport transferMode=„Streamed“ /> Possible transferMode values Buffered Streamed StreamedRequest StreamedResponse Only transport security and no reliable sessions allowed

  26. MSMQ transport MSMQ is different – always has been Duplex MEP over MSMQ-based binding can be achieved by e.g. doing it manually Leverage message headers Access headers through OperationContext in user code Access headers through message inspectors in ServiceModel extensions Use GUID to correlate messages

  27. Real-World Check Common gotchas Nice features, but do I really need them? What about interop, e.g. with Java? Firewalls & NATs Deployment of MSMQ Support for mobile devices Not always is WCF the hammer, as not always everything is a nail

  28. Sample Application: YAPOS ? Yet Another Purchase Order Scenario?No, don’t fear. Let’s bring some coolness into our dev life – talk about developer videos and media Every ‘good’ developer these days needs to deal with online resources and multimedia content MSDN.TV Channel 9 Dotnetpro.tv (German)

  29. Sample Application Scenario Reviewer Media Service Web Server User New Media Service Message Queue Message Queue Upload Service Web Server

  30. Resources Email Christian Weyer christian.weyer@thinktecture.com Weblog Christian Weyer http://blogs.thinktecture.com/cweyer thinktecture http://www.thinktecture.com

More Related