NuSphere Forums Forum Index
NuSphere Forums
Reply to topic
Error: Server: unable to serialize result.


Joined: 03 Jul 2007
Posts: 5
Location: Costa Rica
Reply with quote
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:
Code:

$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?? Confused
View user's profileFind all posts by ecarSend private message


Joined: 26 Sep 2007
Posts: 6
Reply with quote
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.
View user's profileFind all posts by sempsteenSend private message


Joined: 03 Jul 2007
Posts: 5
Location: Costa Rica
Reply with quote
Thanks sempsteen! Very Happy
You gave me an idea about where was my problem.
Below the solution:
Code:

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.');
      }
}
View user's profileFind all posts by ecarSend private message
Error: Server: unable to serialize result.
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
All times are GMT - 5 Hours  
Page 1 of 1  

  
  
 Reply to topic