You can do this by creating SoapExtension and enabling it in your web service client:
System.Web.Services.Protocols.SoapExtension Class (MSDN)
The link above contains the skeleton of a sample code that logs requests / responses to a file.
To enable in your application, add the following to your web.config or app.config:
<webServices> <soapExtensionTypes> <add type="YourNamespace.TraceExtension, AssemblyName" priority="0" group="High"/> </soapExtensionTypes> </webServices>
My own SOAP trace extension is implemented in my own project / assembly. Whenever I need to debug a request / response, I just drop the DLL into the application folder (/ bin for ASP.NET) and add the link to the configuration file as described above.
For instance:
<webServices> <soapExtensionTypes> <add type="DebugTools.SOAP.SOAPTrace.SoapTraceExtension, DebugTools.SOAP" priority="0" group="High"/> </soapExtensionTypes> </webServices>
DebugTools.SOAP.SOAPTrace is the SoapTraceExtension namespace
DebugTools.SOAP is the name of the assembly containing the soap trace code.
source share