CHAPTER 19 ■ INTRODUCTION TO WEB SERVICES WITH SOAP^291
Request received with param1 = abcdefg
Place the service.php file at http://localhost/service.php, or adjust the WSDL file to
reflect your actual script location. The only place you define the service URL is in the WSDL file.
When you run the client, a SOAP envelope is created and sent (posted) to service.php,
which will then compute a response and return another SOAP envelope. To see what informa-
tion is being sent back and forth, use the trace option, as Listing 19-7 demonstrates.
Listing 19-7. Tracing SOAP Interaction
<?php
$client = new SoapClient('demo.wsdl', array('trace'=>true));
$response = $client->Demo('abcdefg');
print($client->__getLastRequest());
print($client->__getLastResponse());
echo $response;
<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" ➥
xmlns:ns1="http://localhost/demo" xmlns:xsd="http://www.w3.org/2001/XMLSchema" ➥
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:SOAP-ENC= "http: ➥
//schemas.xmlsoap.org/soap/encoding/" SOAP-ENV:encodingStyle="http://schemas. ➥
xmlsoap.org/soap/encoding/"><SOAP-ENV:Body><ns1:Demo><param1 xsi:type= ➥
"xsd:string">abcdefg</param1></ns1:Demo></SOAP-ENV:Body></SOAP-ENV:Envelope>
<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" ➥
xmlns:ns1="http://localhost/demo" xmlns:xsd="http://www.w3.org/2001/XMLSchema" ➥
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:SOAP-ENC="http: ➥
//schemas.xmlsoap.org/soap/encoding/" SOAP-ENV:encodingStyle="http://schemas. ➥
xmlsoap.org/soap/encoding/"><SOAP-ENV:Body><ns1:DemoResponse><Result xsi:type= ➥
"xsd:string">Request received with param1 = abcdefg</Result></ns1:DemoResponse> ➥
</SOAP-ENV:Body></SOAP-ENV:Envelope>
Request received with param1 = abcdefg
SoapClient Class Methods and Options
The SoapClient’s constructor takes two parameters: a WSDL file and a list of options.
SoapClient::__construct(mixed $wsdl [, array $options])
Table 19-1 shows the SoapClient::__construct() options.
McArthur_819-9.book Page 291 Friday, February 29, 2008 8:03 AM