Returning An Array of Objects in PHP Web Service

后端 未结 2 1314
你的背包
你的背包 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.

    0 讨论(0)
  • 2021-01-05 05:04

    Here is example both client and server for how to return an array with php web service.It is easy example to understand http://my-source-codes.blogspot.com/2011/10/php-web-service-return-array.html

    0 讨论(0)
提交回复
热议问题