JohnOpincar
JohnOpincar

Reputation: 5813

How Can I Log Exactly The Messages Sent and Received From a WCF Client

Please do not answer using the WCF Trace tool unless give explicit instructions on how to capture the actual message including headers and faults. This link does not work.

Also, do not answer IClientMessageInspector unless you know how to get it to include all headers (which it doesn't) and capture responses that have fault elements that don't parse.

With pre-wcf web services, you could write a SoapExtension that worked flawlessly.

Upvotes: 8

Views: 1955

Answers (3)

lcryder
lcryder

Reputation: 496

A class implementing IEndpointBehavior allows you to trap and log inbound/outbound messages.

See an example here http://msdn.microsoft.com/en-us/library/system.servicemodel.description.iendpointbehavior.applydispatchbehavior.aspx

You'll also need a class implementing IDispatchMessageInspector

Upvotes: 2

JohnOpincar
JohnOpincar

Reputation: 5813

I found this as well:

<system.diagnostics>
    <sources>
        <source name="System.ServiceModel.MessageLogging">
            <listeners>
                <add name="messages"
                type="System.Diagnostics.XmlWriterTraceListener"
                initializeData="c:\log\wcfMessages.svclog" />
            </listeners>
        </source>
    </sources>
</system.diagnostics>

<system.serviceModel>
    <diagnostics>
        <messageLogging
                 logEntireMessage="true"
                 logMalformedMessages="true"
                 logMessagesAtServiceLevel="true"
                 logMessagesAtTransportLevel="true"
                 maxMessagesToLog="1000000"
                 maxSizeOfMessageToLog="10000000"/>
    </diagnostics>
</system.serviceModel>

It's not ideal since you have to use a tool to view the messages but it does seem to capture the actual messages with all headers and faults, etc.

Upvotes: 1

Yaron Naveh
Yaron Naveh

Reputation: 24406

write a custom message encoder. it has access to all headers. deoending on how generic you want your solution to be you may need to write it such that it gets in the ctor the real encoder.

just a few days ago I implemented a "Wrapper encoder" in this thread. that encoder changed the message. you don't need to do this, you can just log it and pass it to the transport as I also did.

Upvotes: 4

Related Questions