发布于 2015-10-07 09:53:26 | 160 次阅读 | 评论: 0 | 来源: 网络整理

38.4. AutoDiscovery.

38.4.1. 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.

Zend_Soap_AutoDiscovery class also supports datatypes mapping from PHP to XSD types.

Here is an example of common usage of the autodiscovery functionality:

class My_SoapServer_Class {
...
}

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

            

38.4.2. Class autodiscovering.

If class is used to provide SOAP server functionality, then the same class should be provided to Zend_Soap_AutoDiscovery for WSDL generation:

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

            

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.

    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.

[注意] 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.

38.4.3. 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:

$autodiscover = new Zend_Soap_AutoDiscover();
$autodiscover->addFunction('function1');
$autodiscover->addFunction('function2');
$autodiscover->addFunction('function3');
...
$autodiscover->handle();

            

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.

[注意] 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.

38.4.4. 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 <-> tns:$className [21].

  • 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.



[21] If Zend_Soap_AutoDiscover object is created with $extractComplexTypes parameter turned off, then classes are translated to xsd:anyType.

Otherwise, tns:$className is used and type is described in details in <types> WSDL section.

最新网友评论  共有(0)条评论 发布评论 返回顶部

Copyright © 2007-2017 PHPERZ.COM All Rights Reserved   冀ICP备14009818号  版权声明  广告服务