25.09.2014 Views

ZEND PHP 5 Certification STUDY GUIDE

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

208 ” XML and Web Services<br />

way data is encoded, or whether the entire SOAP exchange is to be compressed, and<br />

so on.<br />

i<br />

If you are accessing a SOAP service that does not have a WSDL file, it is possible to<br />

create a SOAP client in non-WSDL mode by passing a NULL value to the SoapClient<br />

constructor instead of the location of the WSDL file. In this case, you will have to pass<br />

the URI to the Web service’s entry point as part of the second parameter.<br />

Debugging<br />

SoapClient provides special methods that make it possible to debug messages sent to<br />

and received from a SOAP server. They can be turned on by setting the trace option<br />

to 1 when instantiating a SOAP client object. This, in turn, will make it possible for<br />

you to access the raw SOAP headers and envelope bodies. Here’s an example:<br />

$client = new SoapClient(’http://api.google.com/GoogleSearch.wsdl’,<br />

array(’trace’ => 1));<br />

$results = $client->doGoogleSearch($key, $query, 0, 10, FALSE, ’’,<br />

FALSE, ’’, ’’, ’’);<br />

echo $client->__getLastRequestHeaders();<br />

echo $client->__getLastRequest();<br />

This will output something similar to the following (we trimmed down the text for<br />

the sake of conciseness):<br />

POST /search/beta2 HTTP/1.1<br />

Host: api.google.com<br />

Connection: Keep-Alive<br />

User-Agent: <strong>PHP</strong> SOAP 0.1<br />

Content-Type: text/xml; charset=utf-8<br />

SOAPAction: "urn:GoogleSearchAction"<br />

Content-Length: 900<br />

Licensed to 482634 - Amber Barrow (itsadmin@deakin.edu.au)<br />

<br />

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!