Wrapped document / literal array example

I'm having trouble finding a solid example of a simple array in a wrapped document / literal style.

Consider a PHP function that generates an array to its maximum value.

/** * @param int $max * @return string[] $count */ public function countTo($max) { $array = array(); for ($i = 0; $i < $max; $i++) { $array[] = 'Number: ' . ($i + 1); } return $array; } 

The WSDL types generated for this are:

 <xsd:complexType name="countTo"> <xsd:sequence> <xsd:element name="max" type="xsd:int"/> </xsd:sequence> </xsd:complexType> <xsd:element name="countTo" nillable="true" type="ns:countTo"/> <xsd:complexType name="ArrayOfCount"> <xsd:sequence> <xsd:element minOccurs="0" maxOccurs="unbounded" name="count" nillable="true" type="xsd:string"/> </xsd:sequence> </xsd:complexType> <xsd:complexType name="countToResponse"> <xsd:sequence> <xsd:element name="count" type="ns:ArrayOfCount"/> </xsd:sequence> </xsd:complexType> <xsd:element name="countToResponse" nillable="true" type="ns:countToResponse"/> 

The request in the body will look like this:

 <ns1:countTo> <max>5</max> </ns1:countTo> 

But what does the answer look like, and what is an agreement?

SoapServer is currently generating

 <ns1:countToResponse> <count> <count>Number: 1</count> <count>Number: 2</count> <count>Number: 3</count> <count>Number: 4</count> <count>Number: 5</count> </count> </ns1:countToResponse> 

I'm not sure about the nested count elements. Perhaps it should be instead of item (and the WSDL will need to be updated to make this happen).

 <ns1:countToResponse> <count> <item>Number: 1</item> <item>Number: 2</item> <item>Number: 3</item> <item>Number: 4</item> <item>Number: 5</item> </count> </ns1:countToResponse> 
+8
arrays soap xml php
source share
1 answer

In fact, there is no agreement for this. This is sometimes convenient when you have an item array to name a collection of items . But since your element is called count , this is a bit more complicated, since counts will not be the accepted answer. You can select result , but this will only match if it is also the only element of the container, as in your example.

 <xsd:complexType name="countToResponse"> <xsd:sequence> <xsd:element name="result" type="ns:ArrayOfCount"/> </xsd:sequence> </xsd:complexType> 
+3
source share

All Articles