Returning An Array of Objects in PHP Web Service

后端 未结 2 1313
你的背包
你的背包 2021-01-05 04:30

I want to return an array of article objects in a PHP web service, using nuSOAP v 1.114. This is how I set up the WSDL:

$server->wsdl->addComplexType(         


        
2条回答
  •  别那么骄傲
    2021-01-05 05:01

    I fixed this error. For anyone interested, this seems to be a bug in NuSOAP. You MUST register your returnType for the function as xsd:Array for it to correctly return the array, even though correct WSDL would constitute it as 'tns:ArrayOfArticleType'. I found this in some Drupal source code:

    // Set return value for the service
    $return = array();
    if ($method['#return']) {
      **// Don't let a struct be declared as return parameter, because nusoap will not
      // Send back anything.**
      $return['return'] = 'xsd:'. $method['#return'];
      if ($method['#return'] == 'struct' || $method['#return'] == 'array') {
        $return['return'] = 'xsd:Array';
      }
    } 
    

    Hope this helps someone else who struggled with the same problem.

提交回复
热议问题