Overview

SoapTrace.Net can be configured to log a matched soap request and response pair to an xml file, by default logging is disabled. The name of the file will be based on the date and time the soap message was received - "yyyy-MM-dd HH_mm_ss_fff.xml" - which hopefully should be unique.

Configuring

To configure the logging, open up the Tools->Options dialog and click the "Logging" tab. Here you can configure the logging folder and whether logging is enabled.

The default folder used is "C:\Documents and Settings\[UserName]\Local Settings\Application Data\SoapTrace.Net\Log".

Log File Format

Each log file contains a matched soap request and response.

<SoapMessage> 
  <Time>2005-02-23 20:01:38.05</Time> 
  <Filter> 
    <Server>www.codeproject.com</Server> 
    <Port>80</Port> 
  </Filter> 
  <Source>192.168.1.4:3196</Source> 
  <Request> 
    <Time>2005-02-23 20:01:38.05</Time> 
    <Header><![CDATA[POST /webservices/latest.asmx HTTP/1.1 
User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; MS Web Services Client Protocol 1.1.4322.573) 
Content-Type: text/xml; charset=utf-8 
SOAPAction: "http://codeproject.com/webservices/GetMaxCommentListLength" 
Content-Length: 317 
Expect: 100-continue 
Host: www.codeproject.com 
 
]]></Header> 
    <Message><![CDATA[<?xml version="1.0" encoding="utf-8"?><soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"><soap:Body><GetMaxCommentListLength xmlns="http://codeproject.com/webservices/" /></soap:Body></soap:Envelope>]]></Message> 
  </Request> 
  <Response> 
    <Time>2005-02-23 20:01:38.71</Time> 
    <Header><![CDATA[HTTP/1.1 200 OK 
Server: Microsoft-IIS/5.0 
Date: Wed, 23 Feb 2005 19:47:38 GMT 
X-Powered-By: ASP.NET 
X-AspNet-Version: 1.1.4322 
Cache-Control: no-cache 
Pragma: no-cache 
Expires: -1 
Content-Type: text/xml; charset=utf-8 
Content-Length: 422 
 
]]></Header> 
    <Message><![CDATA[<?xml version="1.0" encoding="utf-8"?><soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"><soap:Body><GetMaxCommentListLengthResponse xmlns="http://codeproject.com/webservices/"><GetMaxCommentListLengthResult>10</GetMaxCommentListLengthResult></GetMaxCommentListLengthResponse></soap:Body></soap:Envelope>]]></Message> 
  </Response> 
</SoapMessage>

Custom Logger

If the logging file format is not good enough for your needs then the logger can be replaced by your own custom one. The custom logger will need to implement the SoapTrace.Core.Diagnostics.ISoapMessageLogger interface.

 /// <summary> 
 /// Interface for all soap message loggers. 
 /// </summary> 
 public interface ISoapMessageLogger 
 { 
  /// <summary> 
  /// Called when a soap request and response have arrived. 
  /// </summary> 
  /// <param name="serverAddressFilter">The remote server's IP address 
  /// or host name used when filtering.</param> 
  /// <param name="serverPortFilter">The remote server's port 
  /// used when filtering. 
  /// </param> 
  /// <param name="requestAndResponse">The soap request and  
  /// response.</param> 
  void Log( string serverAddressFilter,  
   int serverPortFilter,  
   SoapRequestAndResponse requestAndResponse ); 
   
  /// <summary> 
  /// Turns logging on or off. 
  /// </summary> 
  bool Enabled { get; set; } 
   
  /// <summary> 
  /// Sets the logging folder. 
  /// </summary> 
  string Folder { get; set; } 

To make SoapTrace.Net use your custom logger place your assembly dll into the SoapTrace/bin folder, edit the config file found in "C:\Documents and Settings\[UserName]\Local Settings\Application Data\SoapTrace.Net\SoapTrace.Net\[Version]\SoapTrace.exe.user.config" and alter the SoapMessageLogger xml element so it refers to your custom logger type:

  <SoapMessageLogger enabled="true" type="SoapTrace.Core.Diagnostics.SoapMessageLogger, SoapTrace.Core"> 
    <Folder>C:\temp\test</Folder> 
  </SoapMessageLogger> 

There is a corresponding xml element in the SoapTrace.exe.config file which you may want to change so all users will use your custom logger by default.