Zulfiqar's weblog

Architecture, security & random .Net

MetadataExchangeClient message logging

Posted by zamd on April 13, 2009

Is to possible to add a custom behavior in the channel factory created by MetadataExchangeClient?

For example, is it possible to hook a message inspector to the MetadataExchangeClient  so that generated message can be inspected/logged?


It turns that default ctor of MetadataExchangeClient picks the endpoint information (including behavior configuration) from the config file. You can easily achieve this by creating a behavior extension and using it on MEX endpoint. Here are steps:

Step 1: create appropriate config entries



    <endpoint address=http://localhost:9090/mex binding=mexHttpBinding contract=IMetadataExchange behaviorConfiguration=epBv/>




      <behavior name=epBv>






Step2: Create a behavior extension 

public class customBehaviorToEnableMessageLogging : BehaviorExtensionElement


    public override Type BehaviorType


        get { return typeof(InspectorInstallerBehavior); }



    protected override object CreateBehavior()


        return new InspectorInstallerBehavior();



Step3: Create an endpoint behavior to install the message inspector


public class InspectorInstallerBehavior : IEndpointBehavior


    public void ApplyClientBehavior(ServiceEndpoint endpoint, ClientRuntime clientRuntime)


        clientRuntime.MessageInspectors.Add(new MyInspector());




Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: