在Zend PHP中自动生成WSDL复杂类型


Autogenerate WSDL complex types in Zend PHP

我有如下内容…

class getQuickStatusResponse extends Mobile_Response {
    public $trolley = "";
    public $pending = "";
    public $balance = "";
    public $available = "";
    public $tier = "";
    public $lasttierdate = "";
    public $lastissuedate = "";
    public function __construct($traceId) {
        parent::__construct($traceId);
    }
    public function set_data($data=array()) {
        parent::set_data($data);
        if ($data["success"]) {
            $this->trolley = $data['trolley'];
            $this->pending = $data['pending'];
            $this->balance = $data['balance'];
            $this->available = $data['available'];
            $this->tier = $data['tier'];
            $this->lasttierdate = $data['lasttierdate'];
            $this->lastissuedate = $data['lastissuedate'];
        }
    }
}
class Mobile_Response {
    public $traceId = "";
    public $success = false;
    public $msg = "";
    public $pagingOut; 
    public $errorCode = "";
    public $errorMessage = "";
    public function __construct($traceId) {
        //construct-y stuff goes here.
        $this->traceId = $traceId;
        $this->pagingOut = new Paging_Out();
    }
    public function set_data($data=array()) {
        if ($data["success"]) {
            $this->success = true;
        } else {
            $this->errorCode = "SomeCode";
            $this->errorMessage = $data["msg"];
        }
        $this->msg = $data["msg"];
    }
}
class Mobile_Service {
    public function getQuickStatus($campaigncode, $username, $devicename, $traceId) {
        $responseObject = new getQuickStatusResponse($traceId);
       // Do some stuff here.
        return $responseObject;
    }
}

我有一个结束点看起来像这样…

require_once 'Mobile/Blah_Mobile_Service.php';
if (strcmp($_SERVER['QUERY_STRING'],'wsdl') == 0) {
    // WSDL Document creation
    require_once "Zend/Soap/AutoDiscover.php";
    $auto = new Zend_Soap_AutoDiscover(); 
    $auto->setOperationBodyStyle(
            array('use' => 'literal', 'namespace' => 'http://blah.blah
    $auto->setBindingStyle(
            array('style' => 'document', 'transport' => 'http://blah.blah.co.za')
    );
    $auto->setClass('Mobile_Service');
    $auto->handle();
} else {
    // SOAP Document creation
    require_once "Zend/Soap/Server.php";
    $soapServer = new Zend_Soap_Server("http://blah.blah.co.za/services/Mobile/blah-soap.php?wsdl");
    $soapServer->setClass('Mobile_Service');
    $soapServer->handle();
}

我遇到的问题是,自动生成的WSDL将响应类型显示为所有数组,而不是我实际返回的复杂类型。如何强制函数在WSDL上显示为返回特定类型?

任何帮助都将非常感激。我的服务都正常工作了,但是生成WSDL简直要把我逼疯了。

谢谢!

首先-添加PHPDoc注释。然后指出您期望的内容,因为WSDL不是供人类阅读的,而是供程序解析的。

例如:添加php文档注释

error_reporting(E_ALL);
ini_set('display_errors', 1);
set_include_path(get_include_path().';../library/;../library/Zend');
require_once 'Zend/Loader/Autoloader.php';
$autoloader = Zend_Loader_Autoloader::getInstance();
$autoloader->setFallbackAutoloader(true);
/**
 * Class getQuickStatusResponse
 */
class getQuickStatusResponse extends Mobile_Response {
    public $trolley = "";
    public $pending = "";
    public $balance = "";
    public $available = "";
    public $tier = "";
    /**
     *
     *
     * @return string
     */
    public function getAvailable()
    {
        return $this->available;
    }
    /**
     *
     *
     * @param string $available
     *
     * @return getQuickStatusResponse
     */
    public function setAvailable($available)
    {
        $this->available = $available;
    }
    /**
     *
     *
     * @return string
     */
    public function getBalance()
    {
        return $this->balance;
    }
    /**
     *
     *
     * @param string $balance
     *
     * @return getQuickStatusResponse
     */
    public function setBalance($balance)
    {
        $this->balance = $balance;
    }
    /**
     *
     *
     * @return string
     */
    public function getLastissuedate()
    {
        return $this->lastissuedate;
    }
    /**
     *
     *
     * @param string $lastissuedate
     *
     * @return getQuickStatusResponse
     */
    public function setLastissuedate($lastissuedate)
    {
        $this->lastissuedate = $lastissuedate;
    }
    /**
     *
     *
     * @return string
     */
    public function getLasttierdate()
    {
        return $this->lasttierdate;
    }
    /**
     *
     *
     * @param string $lasttierdate
     *
     * @return getQuickStatusResponse
     */
    public function setLasttierdate($lasttierdate)
    {
        $this->lasttierdate = $lasttierdate;
    }
    /**
     *
     *
     * @return string
     */
    public function getPending()
    {
        return $this->pending;
    }
    /**
     *
     *
     * @param string $pending
     *
     * @return getQuickStatusResponse
     */
    public function setPending($pending)
    {
        $this->pending = $pending;
    }
    /**
     *
     *
     * @return string
     */
    public function getTier()
    {
        return $this->tier;
    }
    /**
     *
     *
     * @param string $tier
     *
     * @return getQuickStatusResponse
     */
    public function setTier($tier)
    {
        $this->tier = $tier;
    }
    /**
     *
     *
     * @return string
     */
    public function getTrolley()
    {
        return $this->trolley;
    }
    /**
     *
     *
     * @param string $trolley
     *
     * @return getQuickStatusResponse
     */
    public function setTrolley($trolley)
    {
        $this->trolley = $trolley;
    }
    /**
     *
     *
     * @return string
     */
    public function getErrorCode()
    {
        return $this->errorCode;
    }
    /**
     *
     *
     * @param string $errorCode
     *
     * @return Mobile_Response
     */
    public function setErrorCode($errorCode)
    {
        $this->errorCode = $errorCode;
    }
    /**
     *
     *
     * @return string
     */
    public function getErrorMessage()
    {
        return $this->errorMessage;
    }
    /**
     *
     *
     * @param string $errorMessage
     *
     * @return Mobile_Response
     */
    public function setErrorMessage($errorMessage)
    {
        $this->errorMessage = $errorMessage;
    }
    /**
     *
     *
     * @return string
     */
    public function getMsg()
    {
        return $this->msg;
    }
    /**
     *
     *
     * @param string $msg
     *
     * @return Mobile_Response
     */
    public function setMsg($msg)
    {
        $this->msg = $msg;
    }
    /**
     *
     *
     * @return Paging_Out
     */
    public function getPagingOut()
    {
        return $this->pagingOut;
    }
    /**
     *
     *
     * @param Paging_Out $pagingOut
     *
     * @return Mobile_Response
     */
    public function setPagingOut($pagingOut)
    {
        $this->pagingOut = $pagingOut;
    }
    /**
     *
     *
     * @return boolean
     */
    public function getSuccess()
    {
        return $this->success;
    }
    /**
     *
     *
     * @param boolean $success
     *
     * @return Mobile_Response
     */
    public function setSuccess($success)
    {
        $this->success = $success;
    }
    /**
     *
     *
     * @return string
     */
    public function getTraceId()
    {
        return $this->traceId;
    }
    /**
     *
     *
     * @param string $traceId
     *
     * @return Mobile_Response
     */
    public function setTraceId($traceId)
    {
        $this->traceId = $traceId;
    }
    public $lasttierdate = "";
    public $lastissuedate = "";
    /**
     * @param string $traceId
     */
    public function __construct($traceId) {
        parent::__construct($traceId);
    }
    public function set_data($data=array()) {
        parent::set_data($data);
        if ($data["success"]) {
            $this->trolley = $data['trolley'];
            $this->pending = $data['pending'];
            $this->balance = $data['balance'];
            $this->available = $data['available'];
            $this->tier = $data['tier'];
            $this->lasttierdate = $data['lasttierdate'];
            $this->lastissuedate = $data['lastissuedate'];
        }
    }
}
class Mobile_Response {
    /**
     *
     *
     * @var string
     */
    public $traceId = "";
    /**
     *
     *
     * @var bool
     */
    public $success = false;
    /**
     *
     *
     * @var string
     */
    public $msg = "";
    /**
     *
     *
     * @var Paging_Out
     */
    public $pagingOut;
    /**
     *
     *
     * @var string
     */
    public $errorCode = "";
    /**
     *
     *
     * @var string
     */
    public $errorMessage = "";
    /**
     * @param $traceId
     */
    public function __construct($traceId) {
        //construct-y stuff goes here.
        $this->traceId = $traceId;
        $this->pagingOut = new Paging_Out();
    }
    /**
     * @param array $data
     */
    public function set_data($data=array()) {
        if ($data["success"]) {
            $this->success = true;
        } else {
            $this->errorCode = "SomeCode";
            $this->errorMessage = $data["msg"];
        }
        $this->msg = $data["msg"];
    }
}
class Mobile_Service {
    /**
     * @param string $campaigncode
     * @param string $username
     * @param string $devicename
     * @param string $traceId
     *
     * @return getQuickStatusResponse
     */
    public function getQuickStatus($campaigncode, $username, $devicename, $traceId) {
        $responseObject = new getQuickStatusResponse($traceId);
        // Do some stuff here.
        return $responseObject;
    }
}
class Paging_Out{}
if (strcmp($_SERVER['QUERY_STRING'],'wsdl') == 0) {
    // WSDL Document creation
    require_once "Zend/Soap/AutoDiscover.php";
    $auto = new Zend_Soap_AutoDiscover();
    $auto->setOperationBodyStyle(
        array('use' => 'literal', 'namespace' => 'http://blah.blah')
    );
    $auto->setBindingStyle(
        array('style' => 'document', 'transport' => 'http://blah.blah.co.za')
    );
    $auto->setClass('Mobile_Service');
    $auto->handle();
} else {
    // SOAP Document creation
    require_once "Zend/Soap/Server.php";
    $soapServer = new Zend_Soap_Server("http://blah.blah.co.za/services/Mobile/blah-soap.php?wsdl");
    $soapServer->setClass('Mobile_Service');
    $soapServer->handle();
}

更改WSDL从:

<?xml version="1.0" encoding="UTF-8"?>
<definitions xmlns="http://schemas.xmlsoap.org/wsdl/" xmlns:tns="http://localhost/stack/24489580/"
             xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:xsd="http://www.w3.org/2001/XMLSchema"
             xmlns:soap-enc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
             name="Mobile_Service" targetNamespace="http://localhost/stack/24489580/">
    <types>
        <xsd:schema targetNamespace="http://localhost/stack/24489580/">
            <xsd:element name="getQuickStatus">
                <xsd:complexType>
                    <xsd:sequence>
                        <xsd:element name="campaigncode" type="xsd:anyType"/>
                        <xsd:element name="username" type="xsd:anyType"/>
                        <xsd:element name="devicename" type="xsd:anyType"/>
                        <xsd:element name="traceId" type="xsd:anyType"/>
                    </xsd:sequence>
                </xsd:complexType>
            </xsd:element>
        </xsd:schema>
    </types>
    <portType name="Mobile_ServicePort">
        <operation name="getQuickStatus">
            <documentation>getQuickStatus</documentation>
            <input message="tns:getQuickStatusIn"/>
        </operation>
    </portType>
    <binding name="Mobile_ServiceBinding" type="tns:Mobile_ServicePort">
        <soap:binding style="document" transport="http://blah.blah.co.za"/>
        <operation name="getQuickStatus">
            <soap:operation soapAction="http://localhost/stack/24489580/#getQuickStatus"/>
            <input>
                <soap:body use="literal" namespace="http://blah.blah"/>
            </input>
        </operation>
    </binding>
    <service name="Mobile_ServiceService">
        <port name="Mobile_ServicePort" binding="tns:Mobile_ServiceBinding">
            <soap:address location="http://localhost/stack/24489580/"/>
        </port>
    </service>
    <message name="getQuickStatusIn">
        <part name="parameters" element="tns:getQuickStatus"/>
    </message>
</definitions>

:

<?xml version="1.0"?>
<definitions xmlns="http://schemas.xmlsoap.org/wsdl/" xmlns:tns="http://localhost/stack/24489580/"
             xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:xsd="http://www.w3.org/2001/XMLSchema"
             xmlns:soap-enc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
             name="Mobile_Service" targetNamespace="http://localhost/stack/24489580/">
    <types>
        <xsd:schema targetNamespace="http://localhost/stack/24489580/">
            <xsd:element name="getQuickStatus">
                <xsd:complexType>
                    <xsd:sequence>
                        <xsd:element name="campaigncode" type="xsd:string"/>
                        <xsd:element name="username" type="xsd:string"/>
                        <xsd:element name="devicename" type="xsd:string"/>
                        <xsd:element name="traceId" type="xsd:string"/>
                    </xsd:sequence>
                </xsd:complexType>
            </xsd:element>
            <xsd:complexType name="Paging_Out">
                <xsd:all/>
            </xsd:complexType>
            <xsd:complexType name="getQuickStatusResponse">
                <xsd:all>
                    <xsd:element name="traceId" type="xsd:string"/>
                    <xsd:element name="success" type="xsd:boolean"/>
                    <xsd:element name="msg" type="xsd:string"/>
                    <xsd:element name="pagingOut" type="tns:Paging_Out" nillable="true"/>
                    <xsd:element name="errorCode" type="xsd:string"/>
                    <xsd:element name="errorMessage" type="xsd:string"/>
                </xsd:all>
            </xsd:complexType>
            <xsd:element name="getQuickStatusResponse">
                <xsd:complexType>
                    <xsd:sequence>
                        <xsd:element name="getQuickStatusResult" type="tns:getQuickStatusResponse"/>
                    </xsd:sequence>
                </xsd:complexType>
            </xsd:element>
        </xsd:schema>
    </types>
    <portType name="Mobile_ServicePort">
        <operation name="getQuickStatus">
            <documentation>@param string $campaigncode</documentation>
            <input message="tns:getQuickStatusIn"/>
            <output message="tns:getQuickStatusOut"/>
        </operation>
    </portType>
    <binding name="Mobile_ServiceBinding" type="tns:Mobile_ServicePort">
        <soap:binding style="document" transport="http://blah.blah.co.za"/>
        <operation name="getQuickStatus">
            <soap:operation soapAction="http://localhost/stack/24489580/#getQuickStatus"/>
            <input>
                <soap:body use="literal" namespace="http://blah.blah"/>
            </input>
            <output>
                <soap:body use="literal" namespace="http://blah.blah"/>
            </output>
        </operation>
    </binding>
    <service name="Mobile_ServiceService">
        <port name="Mobile_ServicePort" binding="tns:Mobile_ServiceBinding">
            <soap:address location="http://localhost/stack/24489580/"/>
        </port>
    </service>
    <message name="getQuickStatusIn">
        <part name="parameters" element="tns:getQuickStatus"/>
    </message>
    <message name="getQuickStatusOut">
        <part name="parameters" element="tns:getQuickStatusResponse"/>
    </message>
</definitions>