Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get SOAP XML before __soapCall? [duplicate]

Tags:

php

soap

Is it possible to get the XML generated by SOAP Client before sending it to webservice?

I need this because response from webservice if one of parameters is really wrong I get errors like

Server was unable to read request. 
---> There is an error in XML document (2, 408). 
---> Input string was not in a correct format.

This typically includes firing up tcpmon or some other tcp watcher utility, capturing the webservice call, copy and paste xml to text editor and go to column 408 to see what's the problem.

I'd really like to simplify this process by getting the XML before sending it.

like image 371
Vnuk Avatar asked Jan 07 '10 10:01

Vnuk


1 Answers

It is very, very hard (nigh impossible) to do that. What is much easier is using the SoapClient class' built-in debugging functionality to output the request after it has been sent. You can do that like so:

First, when creating your SOAPClient, enable tracing, like so:

$client = new SoapClient($wsdl, array('trace' => true));

Then do whatever processing is necessary to get ready to make the SOAP call and make it. Once it has been made, the following will give you the request you have just sent:

echo("<pre>"); //to format it legibly on your screen
var_dump($client->__getLastRequestHeaders()); //the headers of your last request
var_dump($client->__getLastRequest()); //your last request

And, if you want to see the response as well, the following should work:

var_dump($client->__getLastResponseHeaders()); //response headers
var_dump($client->__getLastResponse()); //the response
like image 115
benjy Avatar answered Oct 30 '22 02:10

benjy