.NET Log Soap Request on Client

I wrote a post about this a while ago titled "Logging SOAP Messages in .NET".

The easiest way is to use the tools already provided with .NET.

1. Extend the class SoapExtension.

2. override the method ProcessMessage to get a full output of your Soap Request, then output this information to a text file or event log.

public class SoapMessageLogger : SoapExtension
{
  //…
  public override void ProcessMessage(SoapMessage message)
  {
    switch(message.Stage)
    {
      case SoapMessageStage.BeforeDeserialize:
        LogResponse(message);
        break;
      case SoapMessageStage.AfterSerialize:
        LogResponse(message);
        break;
      // Do nothing on other states
      case SoapMessageStage.AfterDeserialize:
      case SoapMessageStage.BeforeSerialize:
      default:
        break;
    }
  }
  //…
}

If it's for debugging purposes I'd just configure the web request to use a proxy and send the entire request though fiddler (http://www.fiddlertool.com) then you can see exactly what's getting transmitted over the wire.