mesut
mesut

Reputation: 2177

Adding IClientMessageInspector globally to any service reference

I Have a .net solution with two seperate projects, one is a class library and other as a web application.

All of my Service References placed in my class library project. and all bindings and endpoint configurations done programmatically.

In my Web Application I Added a IClientMessageInspector and BehaviorExtensionElement by reading this link. How to: Inspect or Modify Messages on the Client

I Don't want to add dbcontext access from within my class library, and all my db operations done at web application project.

Now the problem is I want to log every outgoing service call that place in my class library and I Want to configure this globally. (log to db)

for old style web references I was able to add a Soap Extention like the image below, and all calls logged using TraceExtention class. enter image description here

I need the same ability using Service References.

Upvotes: 1

Views: 1424

Answers (1)

Houssam Hamdan
Houssam Hamdan

Reputation: 908

You can do the same with WCF by adding behavior extensions to web.config.

<system.serviceModel>
 <behaviors>
      <endpointBehaviors>
        <behavior name="ClientBehavior">
          <ClientEndpointBehavior />
        </behavior>
      </endpointBehaviors>
    </behaviors>
    <extensions>
      <behaviorExtensions>
        <add name="ClientEndpointBehavior" type="Custom.WCFMessageInspector, Custom" />
      </behaviorExtensions>
    </extensions>
</system.serviceModel>

1- Custom.WCFMessageInspector is where your client inspection code reside.

2- Add behaviorConfiguration="ClientBehavior" to the client endpoint.

Upvotes: 1

Related Questions