wsdl return an array of complex types
- by Anand
hi,
I have defined a web service that will return the data from my mysql data base.
I have written the web service in php.
Now I have defined a complex type as follows:
$server->wsdl->addComplexType(
'Category',
'complexType',
'struct',
'all',
'',
array(
    'category_parent_id' => array('name' => 'category_parent_id', 'type' => 'xsd:int'),
    'category_child_id' => array('name' => 'category_child_id', 'type' => 'xsd:int'),
    'category_list' => array('name' => 'category_list', 'type' => 'xsd:int')
)
);
The above complex type is a row in a table in my database.
Now my function must send an array of these rows so how do I achieve the same
My code is as follows:
require_once('./nusoap/nusoap.php');
$server = new soap_server;
$server-configureWSDL('productwsdl', 'urn:productwsdl');
// Register the data structures used by the service
$server-wsdl-addComplexType(
    'Category',
    'complexType',
    'struct',
    'all',
    '',
    array(
        'category_parent_id' = array('name' = 'category_parent_id', 'type' = 'xsd:int'),
        'category_child_id' = array('name' = 'category_child_id', 'type' = 'xsd:int'),
        'category_list' = array('name' = 'category_list', 'type' = 'xsd:int')
    )
);
$server-register('getaproduct',                    // method name
    array(),          // input parameters
    //array('return' = array('result' = 'tns:Category')),    // output parameters
    array('return' =  'tns:Category'),    // output parameters
    'urn:productwsdl',                         // namespace
    'urn:productwsdl#getaproduct',                   // soapaction
    'rpc',                                    // style
    'encoded',                                // use
    'Get the product categories'        // documentation
);
function getaproduct()
{
    $conn = mysql_connect('localhost','root','');
     mysql_select_db('sssl', $conn);
     $sql = "SELECT * FROM jos_vm_category_xref";
     $q = mysql_query($sql);
     while($r = mysql_fetch_array($q))
     {
         $items[] = array('category_parent_id'=$r['category_parent_id'],
                              'category_child_id'=$r['category_child_id'],
                              'category_list'=$r['category_list']);
     }
       return $items;
}
// Use the request to (try to) invoke the service
$HTTP_RAW_POST_DATA = isset($HTTP_RAW_POST_DATA) ? $HTTP_RAW_POST_DATA : '';
$server-service($HTTP_RAW_POST_DATA);