Search code examples
iphonenusoapcomplextype

Complex Type Array nusoap and iPhone parsing


When I am accessing an Array of data that is returned from nusoap I encounter duplicate tags. I tried with complex type, but it is not working the way I require i.e, enclosing in specific tags instead of item tags. I am declaring a complex type the following way.

$server->wsdl->addComplexType(
'ProductArray',
'complexType',
'struct',
'all',
'',
array(
    'pid' => array('name' => 'pid', 'type' => 'xsd:string'),
    'pname' => array('name' => 'pname', 'type' => 'xsd:string')
)
);

I register my function:

$server->register('ProdInfo',                    // method name
array('product' => 'tns:product'),          // input parameters
array('return' => 'tns:ProductArray'),    // output parameters
'urn:productcomplextype',                         // namespace
'urn:productcomplextype/ProdInfo',                   // soapaction
'rpc',                                    // style
'encoded',                                // use
'Product Information'        // documentation

);

function

function ProdInfo ($product) {
 //code
 return array('pid'=>$pid,'pname'=>$pname);
}

If I hard code a single return value I get value. But as an array, I am having problems in displaying the correct values. It throws the following output

Array
(
  [pid] => Array
  [pname] => Array
)

Please help

Update

It was due to a problem related to returning the data from the function in an array. It is resolved now after returned correctly. Now the data appears as below

Array
(
 [ProductInfo] => Array
    (
        [0] => Array
            (
                [pid] => 1
                [pname] => Steering
            )

        [1] => Array
            (
                [pid] => 18
                [pname] => Wheel Base
            )
   )

)

This makes it difficult to parse it in iPhone application. In the iPhone response has no data.


Solution

  • the issue has been resolved by simply changing the webservice to return an array. Avoided using complextype.