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.
Viewing Event Logs. Event logging is enabled automatically by default, and there is no mechanism to disable it. Events logged by WCF can be viewed using the Event Viewer.
Windows Communication Foundation (WCF) does not log messages by default. To activate message logging, you must add a trace listener to the System. ServiceModel. MessageLogging trace source and set attributes for the <messagelogging> element in the configuration file.
Tracing is not enabled by default. To activate tracing, you must create a trace listener and set a trace level other than "Off" for the selected trace source in configuration; otherwise, WCF does not generate any traces. If you do not specify a listener, tracing is automatically disabled.
With the service running, right click the project that will contain the WCF client proxy and select Add > Service Reference. In the Add Service Reference Dialog, type in the URL to the service you want to call and click the Go button. The dialog will display a list of services available at the address you specify.
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.
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
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With