You can do this by creating a SoapExtension
and enabling it in your web service client:
System.Web.Services.Protocols.SoapExtension Class (MSDN)
The link above provides a skeleton of 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 tracing extension is implemented in its own project/assembly. Whenever I need to debug the request/response I just drop the DLL in the application folder (/bin for ASP.NET) and add the reference to the config file as above.
For example:
<webServices>
<soapExtensionTypes>
<add
type="DebugTools.SOAP.SOAPTrace.SoapTraceExtension, DebugTools.SOAP"
priority="0" group="High"/>
</soapExtensionTypes>
</webServices>
DebugTools.SOAP.SOAPTrace
is the namespace of the SoapTraceExtension
DebugTools.SOAP
is the name of the assembly containing the soap trace code.