1 / 11

Leveraging the WCF Dispatcher in framework design

Agenda. WCF Dispatcher Functional OverviewWCF Dispatcher Architecture.Inserting custom dispatcher handlers.WCF Behaviors overviewBest Practices.. What does the WCF Dispatcher do?. Instantiates and holds the reference to the service implementation instance.Routes the service invocation from the network (Channel) layer to the concrete method of the implementation instance.Routes the method call results back to the Channel layer for transmission to the client.Handles exceptions and transform32155

yoshi
Download Presentation

Leveraging the WCF Dispatcher in framework design

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. Leveraging the WCF Dispatcher in framework design Eldad Sorek

    2. Agenda WCF Dispatcher Functional Overview WCF Dispatcher Architecture. Inserting custom dispatcher handlers. WCF Behaviors overview Best Practices.

    3. What does the WCF Dispatcher do? Instantiates and holds the reference to the service implementation instance. Routes the service invocation from the network (Channel) layer to the concrete method of the implementation instance. Routes the method call results back to the Channel layer for transmission to the client. Handles exceptions and transforms them into WCF faults.

    4. WCF Dispatcher architecture The WCF dispatcher is actually composed of the following three objects: EndpointDispatcher DispatchRuntime DispatchOperation These objects all implement the pipeline pattern and provide insertable pre and post handlers. Each object’s pipeline connects to the pipeline of the object below and above it.

    5. Pipeline Architectural Pattern

    6. Anatomy of a WCF Service Instance

    7. WCF’s Pre – Post Handler Pattern Implementation The interfaces used to implement the handlers implement the pattern via the following convention and runtime support: The Pre handler is defined in a method named BeforeCall which returns an object called the correlation object. The Dispatcher holds on to the correlation object and passes it to the Post handler. The Post handler is defined in a method named AfterCall. The correlation object is passed via a parameter.

    8. Inserting Handlers into the Dispatcher Pipeline Handlers are inserted or overridden via behaviors. There are three types of behaviors Service Behavior (IServiceBehavior) Endpoint Behavior (IEndpointBehavior) Operation behavior (IOperationBehavior) All behavior interfaces provide the following common methods which are fired in the order listed below. All methods provide the description (metadata) object for the appropriate dispatcher object instance as a method parameter. Validate: Used to validate the existing configuration before the behavior is applied. AddBindingParameters: Allows custom binding parameters to be handed to the WCF endpoint binding by adding them to the binding parameters collection passed as the parameter. ApplyDispatchBehavior: Used to insert the actual handlers into the dispatcher object. The dispatcher object is provided as a method parameter.

    9. Service Behavior (IServiceBehavior) Applies to the entire service host instance. Allows handler insertion to any point in the service host instance. Can be applied via configuration and attributes. Can be used to setup the ServiceHost Context. Best used when a set of handlers needs to be applied conssietntly across the entire ServiceHost instance.

    10. Endpoint Behavior (IEndpointBehavior) Applies to a specific Endpoint instance. Allows handler insertion to the EndpointDispatcher and Dispatch Runtime and all of the DispatchOperation objects. Can be applied via configuration and attributes. Used to apply a consistent set of handlers to all OperationDispatchers in the endpoint. Can be used to insert a custom InstanceProvider, custom InstanceContextProvider, custom InstanceContextInitializers, MessageInspectors, etc... Note: Some of the handlers defined by these interfaces deviate from the standard before – after call pattern.

    11. Operation Behavior (IOperationBehavior) Applies to a specific service operation. Allows handler insertion into the corresponding DispatchOperation. Can be applied via attribute only. Used to insert custom MessageFormatters, CallContextInitializers, ParameterInspectors, etc…

    12. Best Practices Thread Safety: All handlers will be called by multiple threads concurrently. Make sure handler logic is reentrant and all shared state modification is properly serialized. Inject shared state at handler creation time. Make all shared state immutable once created when ever possible. If shared state must be mutable use the appropriate context extension by implementing IExtension<ContextType> on the shared state container object. Make sure the shared state container provides proper thread serialization.

More Related