AutoDiscovery Introduction
SOAP functionality implemented within Zend Framework is intended to
make all steps required for SOAP communications more simple.
SOAP is language independent protocol. So it may be used not only for
PHP-to-PHP communications.
There are three configurations for SOAP applications where Zend
Framework may be utilized:
-
SOAP server PHP application <--->
SOAP client PHP application
-
SOAP server non-PHP application <---> SOAP
client PHP application
-
SOAP server PHP application <--->
SOAP client non-PHP application
We always have to know, which functionality is provided by SOAP
server to operate with it. » WSDL is used
to describe network service API in details.
WSDL language is complex enough (see » http://www.w3.org/TR/wsdl
for the details). So it's difficult to prepare correct WSDL description.
Another problem is synchronizing changes in network service API with
already existing WSDL.
Both these problem may be solved by WSDL autogeneration. A prerequisite for this is a
SOAP server autodiscovery. It constructs object similar to object
used in SOAP server application, extracts necessary information and
generates correct WSDL using this information.
There are two ways for using Zend Framework for SOAP server
application:
-
Use separated class.
-
Use set of functions
Both methods are supported by Zend Framework Autodiscovery functionality.
TheZend_Soap_AutoDiscover class also supports datatypes mapping
from PHP to » XSD types.
Here is an example of common usage of the autodiscovery functionality. The
handle() function generates the WSDL file and posts it to the
browser.
span style="color: #ff0000;">'My_SoapServer_Class'
If you need access to the generated WSDL file either to save it to a file or as an
XML string you can use the dump($filename)
or toXml() functions the AutoDiscover class provides.
Note: Zend_Soap_Autodiscover is not a Soap Server
It is very important to note, that the class
Zend_Soap_AutoDiscover does not act as a
SOAP Server on its own. It only generates the WSDL and serves it
to anyone accessing the url it is listening on.
As the SOAP Endpoint Uri is uses the default
'http://' .$_SERVER['HTTP_HOST'] . $_SERVER['SCRIPT_NAME']
, but this
can be changed with the setUri() function or the
Constructor parameter of Zend_Soap_AutoDiscover class. The
endpoint has to provide a Zend_Soap_Server that listens to
requests.
span style="color: #ff0000;">'wsdl''HelloWorldService'// pointing to the current file here
"http://example.com/soap.php?wsdl"'HelloWorldService'
Class autodiscovering
If class is used to provide SOAP server functionality, then the same class should be
provided to Zend_Soap_AutoDiscover for WSDL generation:
span style="color: #ff0000;">'My_SoapServer_Class'
The following rules are used while WSDL generation:
-
Generated WSDL describes an RPC style Web Service.
-
Class name is used as a name of the Web Service being described.
-
'http://' .$_SERVER['HTTP_HOST'] . $_SERVER['SCRIPT_NAME']
is
used as an URI where the WSDL is available by default but
can be overwritten via setUri() method.
It's also used as a target namespace for all service related names
(including described complex types).
-
Class methods are joined into one » Port Type.
$className . 'Port'
is used as Port Type name.
-
Each class method is registered as a corresponding port operation.
-
Each method prototype generates corresponding Request/Response messages.
Method may have several prototypes if some method parameters are optional.
Note: Important!
WSDL autodiscovery utilizes the PHP docblocks provided by the
developer to determine the parameter and return types. In fact, for scalar types,
this is the only way to determine the parameter types, and for return types, this is
the only way to determine them.
That means, providing correct and fully detailed docblocks is not only best
practice, but is required for discovered class.
Functions autodiscovering
If set of functions are used to provide SOAP server functionality, then the same set
should be provided to Zend_Soap_AutoDiscovery for WSDL
generation:
span style="color: #ff0000;">'function1''function2''function3'
The following rules are used while WSDL generation:
-
Generated WSDL describes an RPC style Web Service.
-
Current script name is used as a name of the Web Service being described.
-
'http://' .$_SERVER['HTTP_HOST'] . $_SERVER['SCRIPT_NAME']
is
used as an URI where the WSDL is available.
It's also used as a target namespace for all service related names
(including described complex types).
-
Functions are joined into one » Port Type.
$functionName . 'Port'
is used as Port Type name.
-
Each function is registered as a corresponding port operation.
-
Each function prototype generates corresponding Request/Response messages.
Function may have several prototypes if some method parameters are optional.
Note: Important!
WSDL autodiscovery utilizes the PHP docblocks provided by the
developer to determine the parameter and return types. In fact, for scalar types,
this is the only way to determine the parameter types, and for return types, this is
the only way to determine them.
That means, providing correct and fully detailed docblocks is not only best
practice, but is required for discovered class.
Autodiscovering Datatypes
Input/output datatypes are converted into network service types using the following
mapping:
-
PHP strings <-> xsd:string
.
-
PHP integers <-> xsd:int
.
-
PHP floats and doubles <-> xsd:float
.
-
PHP booleans <-> xsd:boolean
.
-
PHP arrays <-> soap-enc:Array
.
-
PHP object <-> xsd:struct
.
-
PHP class <-> based on complex type strategy (See:
this section)
[1]
Zend_Soap_AutoDiscoverZend_Soap_Wsdl_Strategy_DefaultComplexTypeZend_Soap_Wsdl_Strategy_Interface$extractComplexTypeZend_Soap_WsdlZend_Soap_Wsdl
manual on adding complex
.
-
type[] or object[] (ie. int[]) <-> based on complex type strategy
-
PHP void <-> empty type.
-
If type is not matched to any of these types by some reason, then
xsd:anyType
is used.
Where
xsd:
is "http://www.w3.org/2001/XMLSchema" namespace,
soap-enc:
is a "http://schemas.xmlsoap.org/soap/encoding/" namespace,
tns:
is a "target namespace" for a service.
WSDL Binding Styles
WSDL offers different transport mechanisms and styles. This affects the
soap:binding
and soap:body
tags within the Binding
section of WSDL. Different clients have different requirements as to what options
really work. Therefore you can set the styles before you call any setClass
or addFunction
method on the AutoDiscover class.
span style="color: #808080; font-style: italic;">// Default is 'use' => 'encoded' and
// 'encodingStyle' => 'http://schemas.xmlsoap.org/soap/encoding/'
'use' => 'literal',
'namespace' => 'http://framework.zend.com')
);
// Default is 'style' => 'rpc' and
// 'transport' => 'http://schemas.xmlsoap.org/soap/http'
'style' => 'document',
'transport' => 'http://framework.zend.com''myfunc1'