Search code examples
phpsoapsoap-clientnusoapsoapserver

Multidimensional associative array as response in NuSOAP


I have some problems with response in SOAP. In general I can not undertand how to get response as multidimensional associative array for my SOAP-client. I used NuSOAP v 1.123 library.

So I have that code in SOAP-server:

$server->wsdl->addComplexType(
    'ReturnDataInside',
    'complexType',
    'struct',
    'all',
    '',
    array(
        'message'               => array('name' => 'message', 'type' => 'xsd:string', 'nillable' => 'true'),
        'value' => array('name' => 'value', 'type' => 'xsd:string', 'nillable' => 'true'),
    )
);

$server->wsdl->addComplexType(
    'ReturnDataOutside',
    'complexType',
    'array',
    'all',
    '',
    array(),
    array(),
    'tns:ReturnDataInside'
);

$server->register('test',
    array('param_1' => 'xsd:int', 'param_2' => 'xsd:string'),
    array('return' => 'tns:ReturnDataOutside')
);

function test($param_1, $param_2)
{
    $data = array(
        'test' => array(
            'message'               => 'string',
            'value'                 => 'string',
        ),
    );

    return $data;
}

My response looks like that:

Array
(
    [0] => Array
        (
            [message] => string
            [value] => string
        )

)

So what to change to get 'test' as a key in my response m.array ?


Solution

  • First of all body of my function was incorrect.

    $data[] = array(
    'message' => 'string',
    'value' => 'string',
    );
    

    And the answer on my quastion is: soap does not send keys for multidimensional arrays.