'NuSOAP - Return multiple arrays of different complexType

I have a NuSOAP Server with the following complex types declared:

$server->wsdl->addComplexType(
    'cargroupAvailableInfo',
    'complexType',
    'struct',
    'all',
    '',
    array(
        'status' => array('name' => 'status', 'type' => 'xsd:int'),
        'status_message' => array('name' => 'status_message', 'type' => 'xsd:string'),
        'model' => array('name' => 'model', 'type' => 'tns:vehicleModel'),
        'charge' => array('name' => 'charge', 'type' => 'tns:vehicleCharge'),
        'extras' => array('name' => 'extras', 'type' => 'tns:PricedEquipsT'),
        'oneWayArea' => array('name' => 'oneWayArea', 'type' => 'tns:oneWayAreaT'),
        'oneWayRegion' => array('name' => 'oneWayRegion', 'type' => 'tns:oneWayRegionT'),
        'mileagePolicy' => array('name' => 'mileagePolicy', 'type' => 'xsd:string'),
        'termsConditions' => array('name' => 'termsConditions', 'type' => 'tns:terms'),
        'tpa' => array('name' => 'tpa', 'type' => 'tns:TPA_Extensions'),
        'locations' => array('name' => 'locations', 'type' => 'tns:Locations')
    )
);

$server->wsdl->addComplexType(
    'cargroupAvailableInfoList',
    'complexType',
    'array',
    '',
    'SOAP-ENC:Array',
    array(),
    array(
        array('ref' => 'SOAP-ENC:arrayType', 'wsdl:arrayType' => 'tns:cargroupAvailableInfo[]')
    ),
    'tns:cargroupAvailableInfo'
);

And the following method registered:

$server->register(
    'getAvailableInfo',                                 // method name
    array('parameters' => 'tns:priceparameters'),       // input parameters
    array('return' => 'tns:cargroupAvailableInfoList'), // output parameters
    'urn:service',                                      // namespace
    'urn:service#getAvailableInfo',                     // soapaction
    'rpc',                                              // style
    'encoded',                                          // use
    'get full price for a reservation'                  // documentation
);

When making a request, I get an response like this (I have removed the extra fields for readability)

<ns1:getAvailableInfoResponse xmlns:ns1="urn:service">
    <return xsi:type="SOAP-ENC:Array" SOAP-ENC:arrayType="tns:cargroupAvailableInfo[2]">
        <item xsi:type="tns:cargroupAvailableInfo">
        </item>
        <item xsi:type="tns:cargroupAvailableInfo">
        </item>
    </return>
</ns1:getAvailableInfoAzureResponse>

So for every car group that is returned, a new "item" node is generated, with the relative information.

Now I want to add an extra array, after the end of the "cargroupAvailableInfoList" array.

I found the following question, that has an answer: Return two types with NuSOAP, but the problem I have with this solution is that I have to change the current structure of the XML response, in order to enclose the "cargroupAvailableInfoList" info in a parent node.

Is there a way to have NuSOAP return the new array after it has finished generating the "cargroupAvailableInfoList" array?

So something like this

<ns1:getAvailableInfoResponse xmlns:ns1="urn:service">
    <return xsi:type="SOAP-ENC:Array" SOAP-ENC:arrayType="tns:cargroupAvailableInfo[2]">
        <item xsi:type="tns:cargroupAvailableInfo">
        </item>
        <item xsi:type="tns:cargroupAvailableInfo">
        </item>        <!-- last item -->
        <packages xsi:type="SOAP-ENC:Array" SOAP-ENC:arrayType="tns:package[2]">
            <package xmlns="" xsi:type="tns:package">
            </package>
            <package xmlns="" xsi:type="tns:package">
            </package>
        </packages>
    </return>
</ns1:getAvailableInfoAzureResponse>

To be clear, the new "packages" array is of a different complexType than the "cargroupAvailableInfoList"



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source