【发布时间】:2011-05-18 08:03:04
【问题描述】:
我正在使用Zend soap autodiscovery 为我的Web 服务器生成一个WSDL 文件。问题是每个 complexType 的每个元素都默认为nillable="true"。我如何根据需要声明元素?我阅读了 PHPDoc,但一无所获。
编辑:代码:
class MyService {
/**
* Identify remote user.
*
* @param LoginReq
* @return LoginResp
*/
public function login($request) {
// Code ....
}
}
class LoginReq {
/** @var string */
public $username;
/** @var string */
public $password;
}
class LoginResp {
/** @var string */
public $errorCode;
}
生成的 WSDL:
<xsd:complexType name="LoginReq">
<xsd:all>
<xsd:element name="username" type="xsd:string" nillable="true"/>
<xsd:element name="password" type="xsd:string" nillable="true"/>
</xsd:all>
</xsd:complexType>
<xsd:complexType name="LoginResp">
<xsd:all>
<xsd:element name="errorCode" type="xsd:string" nillable="true"/>
</xsd:all>
</xsd:complexType>
EDIT2:我刚刚发现要将元素声明为必需/可选,您需要使用minOccurs/maxOcurrs。它们都默认为 1,因此默认情况下每个元素都是必需的。为了声明一个可选元素,你用minOccurs="1" 声明它。 Nillable 仅用于允许元素为空。同样,我如何将一个元素声明为可选(所以 Zend 将 minOccurs="0" 添加到该元素)?
【问题讨论】:
标签: php zend-framework soap