PhpRiot
Become Zend Certified

Prepare for the ZCE exam using our quizzes (web or iPad/iPhone). More info...


When you're ready get 7.5% off your exam voucher using voucher CJQNOV23 at the Zend Store

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:

  1. SOAP server PHP application <---> SOAP client PHP application
  2. SOAP server non-PHP application <---> SOAP client PHP application
  3. 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.

<?php
class My_SoapServer_Class {
...
}

$autodiscover = new Zend_Soap_AutoDiscover();
$autodiscover->setClass('My_SoapServer_Class');
$autodiscover->handle();

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.

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.

<?php
if(isset($_GET['wsdl'])) {
    
$autodiscover = new Zend_Soap_AutoDiscover();
    
$autodiscover->setClass('HelloWorldService');
    
$autodiscover->handle();
} else {
    
// pointing to the current file here
    
$soap = new Zend_Soap_Server("http://example.com/soap.php?wsdl");
    
$soap->setClass('HelloWorldService');
    
$soap->handle();
}

Zend Framework