Pro PHP- Patterns, Frameworks, Testing and More

(vip2019) #1

(^294) CHAPTER 19 ■ INTRODUCTION TO WEB SERVICES WITH SOAP


SoapServer Class Methods and Options


Construction of a SOAP server allows you to define the WSDL the service represents and assign
various options for the service.

SoapServer::__construct(mixed $wsdl [, array $options])

If you pass null to the $wsdl parameter, you are then required to set the uri option. Table 19-3
shows the SoapServer::__construct() options.

The SoapServer class has a number of other methods that allow you to expose your web
services with fine-grained control, as listed in Table 19-4.

Ta b l e 19 - 3. SoapServer::__construct() Options
Option Description
uri The URI of the service in non-WSDL mode
soap_version One of the SOAP_1_X constants
encoding The internal character encoding
actor The actor URI
classmap Allows you to transparently convert WSDL complex types into PHP classes

Ta b l e 19 - 4. Some Other SoapServer Methods
Method Description
SoapServer::addFunction(mixed $functions) Allows you to expose PHP functions to the
web service. The $functions parameter can be
the string name of a function or an array of
function names. The functions must accept
parameters in the order they are declared in
the WSDL file. To return multiple parts, simply
return an associative array with the key names
equal to the part names.
SoapServer::setClass(string $class [,
mixed $args, ...])

Exposes an entire class to the web service. Any
arguments passed after the class name will be
passed to the class’s constructor. All methods
within the class will be accessible by the web
service. The methods in the class should be
non-static, as an instance will be created.
SoapServer::handle([string $soap_request]) The main method in a SoapServer instance.
When called, it will read either the contents of
$HTTP_RAW_POST_DATA or the provided $soap_
request variable. It will parse the SOAP enve-
lope, determine and call the methods required,
and return a response to the client.
SoapServer::fault(string $code,
string $string)

Allows you to throw a SoapFault to indicate a
server error to the client.

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

Free download pdf