Interview Questions

PHP SOAP Extension - What's inside?

SOAP Interview Questions and Answers


(Continued from previous question...)

PHP SOAP Extension - What's inside?

Are you curious about the SOAP message format, or hoping to debug a SOAP client of your own? If so, this section is for you.

The SoapClient() constructor accepts an associative array as its second parameter, as you already saw in the first example. Various options can be passed through this associative array. Here are just two:

* trace – allows the client to store SOAP requests and responses (turned off by default)
* exceptions – allows the client to control the exception mechanism (turned on by default)

Take a look at the following SOAP client example. It is derived from example 5, and shows precisely what is transmitted between the client and the server. In order to retrieve this information we use the SoapClient methods __getLastRequest() and __getLastResponse().

Example (client5.php)
*lt;?php
$client = new SoapClient("stockquote.wsdl",array(
"trace" => 1,
"exceptions" => 0));
$client->getQuote("ibm");
print "<pre>\n";
print "Request :\n".htmlspecialchars($client->__getLastRequest()) ."\n";
print "Response:\n".htmlspecialchars($client->__getLastResponse())."\n";
print "</pre>";
?>

(Continued on next question...)

Other Interview Questions