Search code examples
wcfenterprise-libraryendpointbehavior

What is the order of execution of the endpoint behaviors in WCF?


What is the order of execution of the endpoint behaviors in WCF ? I want the logging to happen only if the request passes the validation block. But in my case, even though the validation fails, the requests are logged by the auditing interceptor.

I have two behavior extensions:

<behaviorExtensions>
<add name="validation"/>
<add name="Auditing"/>
</behaviorExtensions>

and then in my behaviors:

<behaviors>
<endpointBehaviors>
<validation ruleset"AuthenticationRuleSet"/>
<Auditing />
</endpointBehaviors>
</behaviors>

Solution

  • From MSDN

    Evaluation Order

    The System.ServiceModel.ChannelFactory and the System.ServiceModel.ServiceHost are responsible for building the runtime from the programming model and description. Behaviors, as previously described, contribute to that build process at the service, endpoint, contract, and operation.

    The ServiceHost applies behaviors in the following order:

    Service

    Contract

    Endpoint

    Operation

    Within any collection of behaviors, no order is guaranteed.

    The ChannelFactory applies behaviors in the following order:

    Contract

    Endpoint

    Operation

    Within any collection of behaviors, again, no order is guaranteed.

    For validation purposes, maybe you should take a look at Message Inspectors