Joined: 03 Jul 2007 |
Posts: 5 |
Location: Costa Rica |
|
|
Posted: Tue Sep 25, 2007 5:11 pm |
|
|
|
|
|
Please help me on this!
I am doing a web service server but when I returned a complex type such as an array, the system showed this: Error: Server: unable to serialize.
This is the server:
$server->wsdl->addComplexType(
'DataList',
'complexType',
'struct',
'all',
'',
array(
'usr_id' => array('name' => 'usr_id', 'type' => 'xsd:string'),
'description' => array('name' => 'description', 'type' => 'xsd:string')
)
);
$server->wsdl->addComplexType(
'DataListRs',
'complexType',
'array',
'',
'SOAP-ENC:Array',
array(),
array(
array('ref'=>'SOAP-ENC:arrayType','wsdl:arrayType'=>'tns:DataList[]')
),
'tns:DataList'
);
$server->register('echoString', // method name
array('inputString' => 'xsd:string'), // input parameters
array('return' => 'tns:DataListRs'), // output parameters
$ns, // namespace
$ns . '#echoString', // soapaction
'rpc', // style
'encoded', // use
'Return a list of data' // documentation
);
// Use the request to invoke the service
$HTTP_RAW_POST_DATA = isset($GLOBALS['HTTP_RAW_POST_DATA'])
? $GLOBALS['HTTP_RAW_POST_DATA'] : '';
$server->service($HTTP_RAW_POST_DATA);
exit();
function echoString($inputString) {
// some code to the data base connection
$result = mysql_query("SELECT * FROM users WHERE usr_id=".'1', $connectionId);
mysql_close($connectionId);
$result = mysql_fetch_array($result);
return $result;
} else {
return new soap_fault('Client','','Error.');
}
} |
Any suggestions??
|
|
Joined: 26 Sep 2007 |
Posts: 6 |
|
|
|
Posted: Tue Sep 25, 2007 5:46 pm |
|
|
|
|
|
Try mysql_fetch_assoc instead of mysql_fetch_array while getting and returning the mysql data row.
You've defined two elements on your wsdl but mysql_fetch_array returns four (you'll get an array with both associative and number indices).
See http://tr.php.net/mysql_fetch_array for more info.
Hope it helps.
|
|
Joined: 03 Jul 2007 |
Posts: 5 |
Location: Costa Rica |
|
|
Posted: Wed Sep 26, 2007 12:57 pm |
|
|
|
|
|
Thanks sempsteen!
You gave me an idea about where was my problem.
Below the solution:
function echoString($inputString) {
// some code to the data base connection
$result = mysql_query("SELECT * FROM users WHERE usr_id=".'1', $connectionId);
mysql_close($connectionId);
$response = array();
while ($row = mysql_fetch_assoc($result)) {
array_push($response, $row);
}
return $response;
} else {
return new soap_fault('Client','','Error.');
}
}
|
|
|