我正在使用zf2制作肥皂服务器,我遇到了wsdl结构的问题。
我生成的wsdl是这样的:
<definitions>
<types>
<xsd:schema targetNamespace="http://xmlapi.testsoap.com/service">
<xsd:complexType name="RoomPax">
<xsd:all>
<xsd:element name="count" type="xsd:int"/>
<xsd:element name="adults" type="xsd:int"/>
</xsd:all>
</xsd:complexType>
<xsd:complexType name="ArrayOfRoomPax">
<xsd:sequence>
<xsd:element name="item" type="tns:RoomPax" minOccurs="0" maxOccurs="unbounded"/>
</xsd:sequence>
</xsd:complexType>
<xsd:complexType name="GetHotelAvailRQ">
<xsd:all>
<xsd:element name="city" type="xsd:int"/>
<xsd:element name="checkin" type="xsd:string"/>
<xsd:element name="checkout" type="xsd:string"/>
<xsd:element name="rooms" type="tns:ArrayOfRoomPax"/>
<xsd:element name="language" type="xsd:string" nillable="true"/>
</xsd:all>
</xsd:complexType>
<xsd:element name="getHotelAvail">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="getHotelAvailRQ" type="tns:GetHotelAvailRQ"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
<xsd:complexType name="Hotel">
<xsd:all>
<xsd:element name="id" type="xsd:int" nillable="true"/>
<xsd:element name="name" type="xsd:string" nillable="true"/>
</xsd:all>
</xsd:complexType>
<xsd:complexType name="ArrayOfHotel">
<xsd:sequence>
<xsd:element name="item" type="tns:Hotel" minOccurs="0" maxOccurs="unbounded"/>
</xsd:sequence>
</xsd:complexType>
<xsd:complexType name="HotelAvailRS">
<xsd:all>
<xsd:element name="date" type="xsd:string" nillable="true"/>
<xsd:element name="hotels" type="tns:ArrayOfHotel" nillable="true"/>
</xsd:all>
</xsd:complexType>
<xsd:element name="getHotelAvailResponse">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="getHotelAvailResult" type="tns:HotelAvailRS"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
</xsd:schema>
</types>
<portType name="BookingXmlPort">
<operation name="getHotelAvail">
<documentation>This method make a search ... ...</documentation>
<input message="tns:getHotelAvailIn"/>
<output message="tns:getHotelAvailOut"/>
</operation>
</portType>
<binding name="BookingXmlBinding" type="tns:BookingXmlPort">
<soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/>
<operation name="getHotelAvail">
<soap:operation soapAction="http://xmlapi.testsoap.com/service#getHotelAvail"/>
<input>
<soap:body use="literal"/>
</input>
<output>
<soap:body use="literal"/>
</output>
</operation>
</binding>
<service name="BookingXmlService">
<port name="BookingXmlPort" binding="tns:BookingXmlBinding">
<soap:address location="http://xmlapi.testsoap.com/service"/>
</port>
</service>
<message name="getHotelAvailIn">
<part name="parameters" element="tns:getHotelAvail"/>
</message>
<message name="getHotelAvailOut">
<part name="parameters" element="tns:getHotelAvailResponse"/>
</message>
</definitions>
当我在soapUi中测试时,它有一个arrayofRoomPax,它说可以接收零个或更多类型为RoomPAx的项目,如下所示:
<getHotelAvailRQ>
<city>?</city>
<checkin>?</checkin>
<checkout>?</checkout>
<rooms>
<!--Zero or more repetitions:-->
<item>
<count>?</count>
<adults>?</adults>
</item>
</rooms>
<language>?</language>
</getHotelAvailRQ>
我的问题是当我将2个项目放在同一级别并且使用print_r函数测试我的请求对象时,我看到了这个结构
[city] => ?
[checkin] => ?
[checkout] => ?
[rooms] => stdClass Object
(
[item] => Array
(
[0] => stdClass Object
(
[count] => ?
[adults] => ?
)
[1] => stdClass Object
(
[count] => ?
[adults] => ?
)
)
)
而且我真的想要这样的结构来填充我的对象。
[city] => ?
[checkin] => ?
[checkout] => ?
[rooms] => array
(
[0] => stdClass Object
(
[count] => ?
[adults] => ?
)
[1] => stdClass Object
(
[count] => ?
[adults] => ?
)
)
我正在使用此配置的自动发现类:
$wsdl->setOperationBodyStyle(array('use' => 'literal'));
$wsdl->setBindingStyle(array('style' => 'document'));
$wsdl->setComplexTypeStrategy(new \Zend\Soap\Wsdl\ComplexTypeStrategy\ArrayOfTypeSequence);
我该如何解决? 感谢。