Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I see the actual XML generated by PHP SOAP Client Class?

Tags:

php

soap

xml

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.

like image 845
Nick Avatar asked Aug 26 '10 06:08

Nick


People also ask

How do you send XML data in SOAP request?

To send XML content in the body of a request, use the $value$ notation to show that a parameter should be inserted. and the values input1 and input2 as inputs to the Connector Function, a request is made with the values of input1 and input2 substituted into the Request Body.

How do I find SOAP requests?

SOAP messages are transported by HTTP protocol. To view the HTTP request, click RAW at SoapUI Request window (left side). The Request is posted to the web-server. Hence, the POST method of Http is used.

What is SOAP request XML?

SOAP is the Simple Object Access Protocol, a messaging standard defined by the World Wide Web Consortium and its member editors. SOAP uses an XML data format to declare its request and response messages, relying on XML Schema and other technologies to enforce the structure of its payloads.

Is SOAP response XML?

A SOAP message is encoded as an XML document, consisting of an <Envelope> element, which contains an optional <Header> element, and a mandatory <Body> element. The <Fault> element, contained in <Body> , is used for reporting errors.


2 Answers

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)); 
like image 169
shamittomar Avatar answered Oct 01 '22 12:10

shamittomar


$SOAP = new SoapClient($WSDL, array('trace' => true));  $Response = $SOAP->DoRemoteFunction($Data);  echo "REQUEST:\n" . htmlentities($SOAP->__getLastRequest()) . "\n"; 

This will not only print the last request but also make the XML tags visible in the browser.

like image 30
Shankky Avatar answered Oct 01 '22 12:10

Shankky