Search code examples
phpweb-servicessoapsoap-clientsoapserver

Multidimensional array as one of parameter for SOAP request


How to use multidimensional array as on of parameters in SOAP-client for making soap-request ? For my work i used NuSOAP v1.123.

Code that below works fine with simple array, but with multidimensional does not.

So my code in SOAP-client:

$param_array = array(
    array(
        'var_1' => 1,
        'var_2' => 2,
    ),
    array(
        'var_1' => 3,
        'var_2' => 4,
    ),
);

$result = $client->call('test', array('param_1' => 123, 'param_2' => $param_array)); 

My code in SOAP-server:

    $server->wsdl->addComplexType(
            'Return_Array',
            'complexType',
            'struct',
            'all',
            '',
            array(
                'param_1'                   => array('name' => 'param_1', 'type' => 'xsd:int', 'nillable' => 'true'),
                'param_2'               => array('name' => 'param_2', 'type' => 'xsd:int', 'nillable' => 'true'),
            )
        );

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

$server->wsdl->addComplexType(
    'Array',
    'complexType',
    'struct',
    'all',
    '',
    array(
        'var_1'  => array('name' => 'var_1', 'type' => 'xsd:int', 'nillable' => 'true'),
        'var_2'  => array('name' => 'var_2', 'type' => 'xsd:int', 'nillable' => 'true')
);

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

    function test($param_1, $param_2)
    {
        $data = array(
            'test' => array(
            'param_1' => $param_2['var_1'],
            'param_2' => $param_2['var_2'],
            )
        );

        return $data;
    }

With simple array it works fine, but with multidimensional - does not. How to deal with it ?


Solution

  • First of body of my function was incorrect, but for now it's not important. But description is.

    This is correct form of description:

    $server->wsdl->addComplexType(
        'get_string',
        'complexType',
        'struct',
        'all',
        '',
        array(
            'text' => array('name' => 'text', 'type' => 'xsd:string', 'nillable' => 'true'),
        )
    );
    
    $server->wsdl->addComplexType(
        'get_array',
        'complexType',
        'array',
        '',
        'SOAP-ENC:Array',
        array(),
        array(array('ref' => 'SOAP-ENC:arrayType', 'wsdl:arrayType' => 'tns:get_string[]')),
        'tns:get_string'
    );