How to send an multidimension array in Nusoap

2011-11-10
2013-06-06
  • David Eaton
    David Eaton
    2011-11-10

    How can I modify this code so it would return a multidimensional array in Nusoap?

    <?php
      
    $namespace = "localhost/development/requests/getdata2.php?wsdl";
     // call library
     include_once( "/includes/nusoap/lib/nusoap.php");
    
    $server = new soap_server();
    $server->debug_flag = false;
    $server->configureWSDL("WackyWsdl", $namespace);
    $server->wsdl->schemaTargetNamespace = $namespace;
    
    $server->wsdl->addComplexType(
      'Walk',
      'complexType',
      'struct',
      'all',
      '',
      array(
        'WalkId' => array('name' => 'WalkId',
             'type' => 'xsd:int'),
        'WalkTitle' => array('name' => 'WalkTitle',
             'type' => 'xsd:string'),
        'WalkDate' => array('name' => 'WalkDate',
            'type' => 'xsd:date'),
        'WalkDescription' => array('name' => 'WalkDescription',
            'type' => 'xsd:string')
      )
    );
    
     $server->wsdl->addComplexType(
      'Walks',
      'complexType',
      'array',
      '',
      'SOAP-ENC:Array',
      array(),
      array(
        array('ref' => 'SOAP-ENC:arrayType',
             'wsdl:arrayType' => 'tns:Walk[]')
      ),
      'tns:Walk'
    );
    $server->register('GetWalk',                    // method name
      array('WalkId' => 'xsd:int'),          // input parameters
      array('return' => 'tns:Walk'),    // output parameters
      $namespace,                         // namespace
      $namespace . '#GetWalk',                   // soapaction
      'rpc',                                    // style
      'encoded',                                // use
      'Get Specific Walk'        // documentation
    );
    function GetWalk($walkid)
    {
            $test[0]['WalkId']  = $walkid;
            $test[0]['WalkTitle'] = "Title of my long walk";
            $test[0]['WalkDate'] =  date("Y-m-d", time());
            $test[0]['WalkDescription'] = "Really long walk description";
            
            $test[1]['WalkId']  = $walkid;
            $test[1]['WalkTitle'] = "Title of my long walk";
            $test[1]['WalkDate'] =  date("Y-m-d", time());
            $test[1]['WalkDescription'] = "Really long walk description";
            
           return $test; 
           
    //This is how to send a normal array!
      //return array(
      //  "WalkId" => $walkid,
      //  "WalkTitle" => "Title of my long walk",
      //  "WalkDate" => date("Y-m-d", time()),
      //  "WalkDescription" => "Really long walk description"
      ///);
      
      
    }
    
     $HTTP_RAW_POST_DATA = isset($HTTP_RAW_POST_DATA) ? $HTTP_RAW_POST_DATA : '';
     $server->service($HTTP_RAW_POST_DATA);
    
     ?>
    

    The code above currently on returns a single array.   Can anyone please tell me what I am doing wrong ?

    Thanks in advance.

     
  • Tomasz Fidos
    Tomasz Fidos
    2013-05-29

    I think you shoud use "Walks" not "Walk" as an output type

    $server->register('GetWalk',                    // method name
      array('WalkId' => 'xsd:int'),          // input parameters
      array('return' => 'tns:Walks'),    // output parameters
      $namespace,                         // namespace
      $namespace . '#GetWalk',                   // soapaction
      'rpc',                                    // style
      'encoded',                                // use
      'Get Specific Walk'        // documentation
    );