.NET Log Soap Request on Client

后端 未结 6 609
野趣味
野趣味 2021-01-05 09:49

I\'m consuming a third party .NET WebService in my client application. For debugging purposes I want to capture the SOAP requests that are being sent from my server. How w

6条回答
  •  借酒劲吻你
    2021-01-05 10:32

    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;
        }
      }
      //…
    }
    

提交回复
热议问题