Debugging SOAP Request/Response messages

Problem

Viewing the raw SOAP requests and responses being sent to the Salesforce Partner API by S4S/G4S?

Solution

The following solution requires a S4S or G4S build created on or after the 16th of May 2016 to access the inbuilt TraceSoapExtension.

Enabling SOAP level tracing will expose the Salesforce credentials and Session ID in the TraceSoapExtension.

Note that this should only be utilized for debugging due to the overhead of copying the XML streams

  1. Add the TraceSoapExtension in the .config file

    Config
    <configuration>
     
    <!-- ... -->
     
      <system.web>
        <webServices>
          <soapExtensionTypes>
            <add type="FuseIT.G4S.SalesforceConnector.TraceSoapExtension, FuseIT.G4S.SalesforceConnector" priority="1" group="0"/>
          </soapExtensionTypes>
        </webServices>
      </system.web>
      
    </configuration>
  2. Make the Salesforce SOAP call of interest
  3. Access the most recent SOAP request and response via the TraceSoapExtension static properties.

    Access SOAP Request/Response
    SalesforceSession session = \\ Establish a Salesforce Session. This will make a SOAP API call to the login() web method plus some calls for metadata
    
    Assert.IsNotNull(TraceSoapExtension.XmlRequest);
    System.Diagnostics.Debug.WriteLine(TraceSoapExtension.XmlRequest.OuterXml);
    
    Assert.IsNotNull(TraceSoapExtension.XmlResponse);
    System.Diagnostics.Debug.WriteLine(TraceSoapExtension.XmlResponse.OuterXml);