Pro PHP- Patterns, Frameworks, Testing and More

(vip2019) #1
CHAPTER 20 ■ ADVANCED WEB SERVICES^303

$server->addFunction('GetCallDetailRecords');
$server->handle();

Listing 20-3 shows an example of calling the server in Listing 20-2.

Listing 20-3. Creating a SOAP Client for the Phone Company Web Service (PhoneClient.php)

$client = new SoapClient('PhoneCompany.wsdl', array('trace'=>true));

var_dump($client->__getTypes());

try {
$response = $client->GetCallDetailRecords('A-121-332');
var_dump($response);
} catch (SoapFault $sf) {
var_dump($sf);
print($client->__getLastRequest());
print($client->__getLastResponse());
}

array(2) {
[0]=>
string(95) "struct CallDetailRecord {
dateTime StartTime;
int Duration;
string Caller;
string Callee;
}"
[1]=>
string(40) "CallDetailRecord CallDetailRecordArray[]"
}
array(2) {
[0]=>
object(stdClass)#2 (4) {
["StartTime"]=>
string(23) "20070510T21:48:00-07:00"
["Duration"]=>
int(3600)
["Caller"]=>
string(12) "123-123-1234"
["Callee"]=>
string(12) "123-123-1235"
}
[1]=>
object(stdClass)#3 (4) {
["StartTime"]=>
string(23) "20070510T22:58:00-07:00"
["Duration"]=>

McArthur_819-9.book Page 303 Friday, February 29, 2008 8:03 AM

Free download pdf