wsdl return an array of complex types

Posted by Anand on Stack Overflow See other posts from Stack Overflow or by Anand
Published on 2010-01-08T12:12:43Z Indexed on 2010/03/23 6:53 UTC
Read the original article Hit count: 452

Filed under:
|

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);

© Stack Overflow or respective owner

Related posts about wsdl

Related posts about xml-schema