8

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.

SliverNinja - MSFT
  • 31,051
  • 11
  • 110
  • 173
JohnOpincar
  • 5,620
  • 3
  • 35
  • 38

3 Answers3

4

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.

Community
  • 1
  • 1
Yaron Naveh
  • 23,560
  • 32
  • 103
  • 158
  • I'll have to give this a try later. I'd really like to log directly into our existing log in a human-readable format. – JohnOpincar May 22 '12 at 16:17
  • you need wcf logging, not wcf tracing. see here http://msdn.microsoft.com/en-us/library/ms730064.aspx then instead of System.Diagnostics.XmlWriterTraceListener put your own class that implements the interface. I have not done it myself though – Yaron Naveh May 22 '12 at 16:22
  • I finally ended up doing this -- another example of how incomplete and painful WCF is. – JohnOpincar Apr 19 '13 at 15:46
  • As example of custom message encoder you can refer my project https://github.com/capslocky/WcfSoapLogger – Adam Oct 08 '18 at 12:23
2

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

lcryder
  • 486
  • 2
  • 8
1

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.

JohnOpincar
  • 5,620
  • 3
  • 35
  • 38