tags:

views:

48

answers:

4

Consider this example SOAP Client script:

$SOAP = new SoapClient($WDSL); // Create a SOAP Client from a WSDL

// Build an array of data to send in the request.
$Data = array('Something'=>'Some String','SomeNumber'=>22); 

$Response = $SOAP->DoRemoteFunction($Data); // Send the request.

On the last line, PHP takes the arguments from the array you specified, and, using the WSDL, builds the XML request to send, then sends it.

How can I get PHP to show me the actual XML it's built?

I'm troubleshooting an application and need to see the actual XML of the request.

+2  A: 

Use getLastRequest. It returns the XML sent in the last SOAP request.

echo "REQUEST:\n" . $SOAP->__getLastRequest() . "\n";

And remember, this method works only if the SoapClient object was created with the trace option set to TRUE. Therefore, when creating the object, use this code:

$SOAP = new SoapClient($WDSL, array('trace' => 1));
shamittomar
+1  A: 

You need to enable tracing when you create your SoapClient. Like so:

$SOAP = new SoapClient($WSDL, array('trace' => true));

$Data = array('Something'=>'Some String','SomeNumber'=>22); 

Then call the __getLastRequest method after you've made a service call to see the XML.

$Response = $SOAP->DoRemoteFunction($Data);
echo $SOAP->__getLastRequest();

This will output the request XML.

More reading: http://www.php.net/manual/en/soapclient.getlastrequest.php

Ezequiel Muns
A: 

if you are running the client locally, Fiddler is a great implementation agnostic way of looking at the messages on the wire.

If you are running it remotely then you could use something like Apache TCPMON Standalone or through eclipse*

*just linking to the first hit from Google

Pratik Bhatt
A: 

$SOAP = new SoapClient($WSDL, array('trace' => true));

$Response = $SOAP->DoRemoteFunction($Data);

echo "REQUEST:\n" . htmlentities($client->__getLastRequest()) . "\n";

this will not print the last request but also make the xml tags visible in the browser

Shankky