Search code examples
wcfloggingsoap

How to log soap response which are sent by WCF


I am new to WCF. To log the SOAP request, I am referring to the following object: OperationContext.Current.RequestContext.RequestMessage and I flush it down to a file.

How can I achieve a similar functionality to log the SOAP response that will be sent by the OperationContract?


Solution

  • There are two ways of doing this.

    1. Implement WCF Tracing. This is more usually used for debugging rather than logging per se, because of the volume of data which is generated. However, the entire SOAP payloads of all requests and responses received will be logged. To view the logs you will need to use the WCF Trace Viewer.

    2. Implement service-or-client-side message inspectors to gain access to either the request message before handling or the response message before sending. This is a more targetted, fine-grained approach and is recommended over the WCF Tracing approach.

    A third means is documented here: https://stackoverflow.com/a/52620878/569662