Php 创建具有复杂类型的Zend Soap服务
我使用Zend版本1.11创建了以下Web服务 我想将Php 创建具有复杂类型的Zend Soap服务,php,xml,web-services,zend-framework,zend-soap,Php,Xml,Web Services,Zend Framework,Zend Soap,我使用Zend版本1.11创建了以下Web服务 我想将xsd是默认名称空间的名称空间更改为s。 如何更改任何名称空间别名 xmlns:xsd="http://www.w3.org/2001/XMLSchema" 到 如何更改默认消息部分: 默认生成为getGroupIn应为getGroupRequest 及 getGroupOut应该是getGroupResponse 是否可以按照W3C更改WSDL顺序 WSDL的结构是 types (1) portType (1) binding (1) s
xsd
是默认名称空间的名称空间更改为s
。
如何更改任何名称空间别名
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
到
如何更改默认消息部分:
默认生成为getGroupIn
应为getGroupRequest
及
getGroupOut
应该是getGroupResponse
是否可以按照W3C更改WSDL顺序
WSDL的结构是
types (1)
portType (1)
binding (1)
service (1)
message (2)
但应该是
types
messages
portTypes
bindings
services
WSDL
if(isset($_GET['wsdl'])) {
$autodiscover = new Zend_Soap_AutoDiscover('Zend_Soap_Wsdl_Strategy_ArrayOfTypeComplex');
$autodiscover->setUri("http://localhost/ZendSoap/services/testwsdl.php");
$autodiscover->setClass('Test');
$autodiscover->handle();
} else {
$soap = new Zend_Soap_Server("http://localhost/ZendSoap/services/testwsdl.php?wsdl"); // this current file here
$soap->setClass('Test');
$soap->handle();
}
class Person
{
/** @var string */
public $name = '';
}
class Group
{
/** @var Person[] */
public $persons;
}
class Test
{
/**
* @return Group
*/
public function getGroup()
{
$group = new Group();
$person = new Person();
$person->name = "Annah";
$group->persons[] = $person;
$person = new Person();
$person->name = "Sarah";
$group->persons[] = $person;
return $group;
}
}
我的WSDL如下所示:
<?xml version="1.0"?>
<definitions xmlns="http://schemas.xmlsoap.org/wsdl/" xmlns:tns="http://localhost/ZendSoap/services/testwsdl.php" 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="Test" targetNamespace="http://localhost/ZendSoap/services/testwsdl.php">
<types>
<xsd:schema targetNamespace="http://localhost/ZendSoap/services/testwsdl.php">
<xsd:complexType name="ArrayOfPerson">
<xsd:complexContent>
<xsd:restriction base="soap-enc:Array">
<xsd:attribute ref="soap-enc:arrayType" wsdl:arrayType="tns:Person[]"/>
</xsd:restriction>
</xsd:complexContent>
</xsd:complexType>
<xsd:complexType name="Person">
<xsd:all>
<xsd:element name="name" type="xsd:string"/>
</xsd:all>
</xsd:complexType>
<xsd:complexType name="Group">
<xsd:all>
<xsd:element name="persons" type="tns:ArrayOfPerson" nillable="true"/>
</xsd:all>
</xsd:complexType>
</xsd:schema>
</types>
<portType name="TestPort">
<operation name="getGroup">
<documentation>@return Group</documentation>
<input message="tns:getGroupIn"/>
<output message="tns:getGroupOut"/>
</operation>
</portType>
<binding name="TestBinding" type="tns:TestPort">
<soap:binding style="rpc" transport="http://schemas.xmlsoap.org/soap/http"/>
<operation name="getGroup">
<soap:operation soapAction="http://localhost/ZendSoap/services/testwsdl.php#getGroup"/>
<input>
<soap:body use="encoded" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" namespace="http://localhost/ZendSoap/services/testwsdl.php"/>
</input>
<output>
<soap:body use="encoded" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" namespace="http://localhost/ZendSoap/services/testwsdl.php"/>
</output>
</operation>
</binding>
<service name="TestService">
<port name="TestPort" binding="tns:TestBinding">
<soap:address location="http://localhost/ZendSoap/services/testwsdl.php"/>
</port>
</service>
<message name="getGroupIn"/>
<message name="getGroupOut">
<part name="return" type="tns:Group"/>
</message>
</definitions>
@返回组
名称空间在Zend\u Soap\u Wsdl
类中硬编码。我的建议是编写自己的类来扩展Zend\u Soap\u Wsdl
,并用自己的构造函数替换构造函数。这肯定会解决你问题的第一部分
至于WSDL生成的其他方面,我认为您需要一步一步地进行Zend_Soap_WSDL
,这将进行实际的生成,并找出需要更改哪些位才能以您想要的方式生成WSDL。当您确定哪些代码位需要更改时,请在子类中重新编写该方法,然后使用子类来生成WSDL,而不是使用Zend\u Soap\u WSDL
要使用自己的类生成WSDL,需要将类名作为第三个参数传递给
Zend\u Soap\u AutoDiscover
构造函数。您的类还需要通过自动加载器进行定位。我想知道的另一件事是,旧版本或Zend的问题,还是在新版本的Zend中得到了解决?我正在使用Zend Ver。1.11我不使用ZF2,但我只是看了一下github上的WSDL类,虽然代码在将硬编码的内容从方法中分离出来并转换为常量方面更好,但我认为您仍然需要创建自己的子类来更改名称空间前缀等内容。因此我认为您最终可以得到一个更干净的解决方案,但我不认为这会减少任何努力。
<?xml version="1.0"?>
<definitions xmlns="http://schemas.xmlsoap.org/wsdl/" xmlns:tns="http://localhost/ZendSoap/services/testwsdl.php" 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="Test" targetNamespace="http://localhost/ZendSoap/services/testwsdl.php">
<types>
<xsd:schema targetNamespace="http://localhost/ZendSoap/services/testwsdl.php">
<xsd:complexType name="ArrayOfPerson">
<xsd:complexContent>
<xsd:restriction base="soap-enc:Array">
<xsd:attribute ref="soap-enc:arrayType" wsdl:arrayType="tns:Person[]"/>
</xsd:restriction>
</xsd:complexContent>
</xsd:complexType>
<xsd:complexType name="Person">
<xsd:all>
<xsd:element name="name" type="xsd:string"/>
</xsd:all>
</xsd:complexType>
<xsd:complexType name="Group">
<xsd:all>
<xsd:element name="persons" type="tns:ArrayOfPerson" nillable="true"/>
</xsd:all>
</xsd:complexType>
</xsd:schema>
</types>
<portType name="TestPort">
<operation name="getGroup">
<documentation>@return Group</documentation>
<input message="tns:getGroupIn"/>
<output message="tns:getGroupOut"/>
</operation>
</portType>
<binding name="TestBinding" type="tns:TestPort">
<soap:binding style="rpc" transport="http://schemas.xmlsoap.org/soap/http"/>
<operation name="getGroup">
<soap:operation soapAction="http://localhost/ZendSoap/services/testwsdl.php#getGroup"/>
<input>
<soap:body use="encoded" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" namespace="http://localhost/ZendSoap/services/testwsdl.php"/>
</input>
<output>
<soap:body use="encoded" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" namespace="http://localhost/ZendSoap/services/testwsdl.php"/>
</output>
</operation>
</binding>
<service name="TestService">
<port name="TestPort" binding="tns:TestBinding">
<soap:address location="http://localhost/ZendSoap/services/testwsdl.php"/>
</port>
</service>
<message name="getGroupIn"/>
<message name="getGroupOut">
<part name="return" type="tns:Group"/>
</message>
</definitions>