While trying to diagnose a problem, I encountered the need to see the actual XML payload being send by my SOAP Client to the Server. I cannot run tcpdump or similar on my host.
I discovered that PHP's SoapClient function provides the following calls:
SoapClient::__getLastRequest - Returns last SOAP request
SoapClient::__getLastRequestHeaders() - Returns the SOAP headers from the last request
SoapClient::__getLastResponse() - Returns last SOAP response
SoapClient::__getLastResponseHeaders() - Returns the SOAP headers from the last response
With Drupal SOAP Client, the PHP SoapClient object is owned and controlled by the DrupalSoapClient object which doesn't offer such calls.
I have made a simple modification which works as follows:
1) Set trace to TRUE in the $options array that is passed to your DrupalSoapClient instance - e.g.
$options = array('trace' => TRUE);
$client = soapclient_init_client(<soap_url>,<use_wsdl?>, $options);
$client->call(<function>,<args>);
#etc..
2) Whenever DrupalSoapClient->call method is called, if 'trace' == TRUE in the $options array, then it sets the Drupal Message to warn that tracing is enabled and dumps the query/response data into the 'dblog' (Watchdog).
Heres the code I added.. Which is included in the attached patch file.
if ( $this->options['trace'] === TRUE ) {
try {
drupal_set_message("SOAP Tracing Enabled - See the ". l('Watchdog Log','admin/reports/dblog'). " for the data.",'warning');
watchdog("soapclient","SOAP Request Header: !msg",array( '!msg' => htmlentities($this->client->__getLastRequestHeaders()), WATCHDOG_DEBUG));
watchdog("soapclient","SOAP Request Body: !msg",array( '!msg' => htmlentities($this->client->__getLastRequest()), WATCHDOG_DEBUG));
watchdog("soapclient","SOAP Response Header: !msg",array( '!msg' => htmlentities($this->client->__getLastResponseHeaders()), WATCHDOG_DEBUG));
watchdog("soapclient","SOAP Response Body: !msg",array( '!msg' => htmlentities($this->client->__getLastResponse()), WATCHDOG_DEBUG));
}
catch (Exception $e) {
$result['#error'] = t($e->getMessage());
return $result;
}
}
I suppose an improvement on this would be to create an addition method on the DrupalSoapClient object which allows the end user to specify what tracing they want and pass the output for them to process, but this did the trick for me.
As a side note - My problem turned out that I was trying to send an argument called 'authToken' when in fact the WSDL definition was 'AuthToken' ... If you try to send an argument via SOAP which does not match one that is declared in the WSDL definition then PHP's SOAP implementation will not include it in the outbound request. It does this silently.
I hope this helps someone else :-)
| Comment | File | Size | Author |
|---|---|---|---|
| drupal_soap_client-add_tracing.patch | 1.44 KB | Ovation1357 |