user986491
user986491

Reputation: 11

how to capture outgoing soapclient request?

I've tried a couple of potential solutions (using ob_ for instance) I found, but not having any luck.

I'd like to be able to display to screen the outgoing request in order to debug it.

Upvotes: 1

Views: 2482

Answers (1)

HNygard
HNygard

Reputation: 4796

I've debugging of SoapClient by extending the SoapClient and overriding methods like _soapcall() and _doRequest(). In my projects I have a logger that writes the XML/arguements to a file.

My example includes both _soapCall() and _doRequest(). I print out different stuff in both methods. Might suit your debugging needs. I like to read the $args output from __soapCall() and like to copy the XML into SoapUI for validation (Alt+V). HTTP headers might also be interesting if you are debugging authentication or other error situations.

class MySoapClient extends SoapClient {
    public function __soapCall ($function_name, array $args, array $options = null, $input_headers = null, array &$output_headers = null) {
        // Dump $args to file, browser printout, console, etc
        var_dump($args);

        parent::__soapCall ($function_name, $args, $options, $input_headers, $output_headers);

        // XML request and response:
        var_dump($this->__getLastRequest()); // Request sent to server
        var_dump($this->__getLastResponse()); // Response from server

        // HTTP headers:
        var_dump($this->__getLastRequestHeaders());
        var_dump($this->__getLastResponseHeaders());
    }

    public function __doRequest ( string $request , string $location , string $action , int $version, int $one_way = 0 ) {
        var_dump($request); // XML

        $response = parent::__doRequest ($request, $location, $action, $version, $one_way);
        var_dump($response); // XML

        return $response;
    }
}

$webservice = new MySoapClient('http://example.com/myservice?wsdl');
$webservice->__soapCall('SomeOperation', array($someArguments));

A logger can be used instead for var_dump:

logger('debug', $this->__getLastRequest());

Upvotes: 2

Related Questions