Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is WCF dispatch pipeline message flow

I'm trying to gain a better understanding of WCF's dispatch process in particular the impact and effect on the various extensibility points. From the web pages listed at the bottom, it appears that WCF will do the following in the stated sequence once a message is passed to the dispatcher by the channel stack.

  1. Message Inspector
  2. Operation Selector
  3. Message Formatting
  4. Parameter Inspector
  5. Operation Invoker.

I'm trying to find some options to resolve an issue I have and one way I'm thinking of is to use a combination of Message Inspector, Operation Selector, Message Formatting and Operation Invoker. Unfortunately, my observation seems to indicate the sequence of execution is as follows instead:

  1. Operation Selector
  2. Message Inspector
  3. Operation Invoker (AllocateInputs())
  4. Message Formatting
  5. Parameter Inspector
  6. Operation Invoker (Invoke())

I can understand the slight difference where a custom invoker AllocateInputs() method is called before formatting the message as the Message Formatting section is essentially deserialising the given message into a set of method arguments to be passed on to the appropriate operation and the invoker's AllocateInputs() method specifies how many parameters are expected.

The part that throws me is the inversion of sequence between Message Inspector and Operation Selector. It sounds logical to me for Message Inspectors to be run through first as they act on the message whereas Operation Selector determines which service operation the message is targeted for.

Questions:

  • Is that due to different versions or releases of WCF?
  • Is this because WCF does not actually specify extensibility points execution sequence?

Reference pages:
Extending WCF to support custom data formats - Zulfiqar's weblog
Extending WCF with Custom Behaviours - MSDN Service Station December 2007
Message Flow Interception Points - Nicholas Allen's Indigo Blog

Note: My apologies for not providing links, can't have more than one since I'm still a noob. =)

like image 319
hg lim Avatar asked Dec 06 '09 05:12

hg lim


1 Answers

To determine the actual order that the code executes in I would recommend turning on Tracing for WCF and look over the generated trace logs. This can be enabled by adding this to the config file:

<configuration>
    <system.diagnostics>
        <sources>
            <source name="System.ServiceModel"
                    switchValue="Information, ActivityTracing"
                    propagateActivity="true">
                <listeners>
                    <add name="traceListener"
                        type="System.Diagnostics.XmlWriterTraceListener"
                        initializeData= "c:\log\Traces.svclog" />
                </listeners>
            </source>
        </sources>
    </system.diagnostics>
</configuration>

As far as the extensibility points in WCF, Carlos Figueira (one of the engineers of WCF at Microsoft) has a post detailing almost all of the extensibility points in WCF ( http://blogs.msdn.com/b/carlosfigueira/archive/2011/03/14/wcf-extensibility.aspx ).

In the WCF Runtime section of this post the ordering is listed as such:

1.2. WCF Runtime
    1.2.1. Message interception 
        1.2.1.1. I[Client/Dispatch]MessageInspector 
        1.2.1.2. IParameterInspector 
    1.2.2. Mapping between message and operation parameter 
        1.2.2.1. I[Client/Dispatch]MessageFormatter 
    1.2.3. Mapping between message and CLR operations 
        1.2.3.1. I[Client/Dispatch]OperationSelector 
        1.2.3.2. IOperationInvoker  
    1.2.4. Instance creation 
        1.2.4.1. IInstanceProvider 
        1.2.4.2. IInstanceContextProvider 
    1.2.5. Error handling 
        1.2.5.1. IErrorHandler 
    1.2.6. Others 
        1.2.6.1. ICallContextInitializer 
        1.2.6.2. IChannelInitializer 
        1.2.6.3. IInteractiveChannelInitializer 

I think between the two the order of operations in WCF should become clear.

like image 147
Phil Patterson Avatar answered Nov 03 '22 15:11

Phil Patterson