Nusoap: problemas cuando devuelve array de datos

[email protected] ("Federica Pavese")
Newsgroups php.general.es
Message-ID <68087F84E4674496B6094B0B67605D0F@informatica1>
Estimados todos:
Estoy haciendo un web service (cliente y servidor) en php con nusoap y sigo 
con algunos problemas para ver el resultado, si éste es un array. Si es un 
dato simple (entero, string, etc) lo hace perfecto, con lo que descarto 
errores de conexión a la base de datos y errores de sintaxis básicos.

En el archivo cliente hago algunas comprobaciones (a modo de debug) y el 
mensaje de error que obtengo es:

el resultado es un array
Array con datos.
Error 1: SOAP-ENV:Server: unable to serialize result


Copio el código más abajo. Gracias de antemano por cualquier ayuda que 
puedan darme !!!

Lic. Federica Pavese
Dpto. de Informática
Bolsa de Comercio de Mendoza S.A.
Tel. (54) (261) 449-6112
----------------------------------------------------------------------------------------
/*** ARCHIVO SERVIDOR: servidor7.php ******/
<?
require_once('funciones.lib');
require_once('/usr/local/lib/nusoap/lib/nusoap.php');

$miURL = 'http://xxx.xxx.xxx.xxx/ws/servidor';
$server = new soap_server();
$server->configureWSDL('ws_bolsa', $miURL);
$server->wsdl->schemaTargetNamespace=$miURL;

$server->wsdl->addComplexType('Contrato',
    'complexType',
    'struct',
    'all',
    '',
    array(
       'nro_operacion' => array('name' => 'nro_operacion', 'type' => 
'xsd:int'),
       'cantidad' => array('name' => 'cantidad','type' => 'xsd:double'),
       'precio' => array('name' => 'precio', 'type' => 'xsd:double'),
       'nro_inv' => array('name' => 'nro_inv','type' => 'xsd:string')
        ));
$server->wsdl->addComplexType('estructura',
        'complexType',
        'array',
        '',
        'SOAP-ENC:Array',
        array(),
        array(
        array('ref' => 'SOAP-ENC:arrayType', 'wsdl:arrayType' => 
'tns:Contrato[]')), 'tns:Contrato');

$server->register('busqueda', array('nro_operacion' => 'xsd:int'), 
array('return' => 'tns:estructura'), $miURL);

$server->service($HTTP_RAW_POST_DATA);
?>



/***** ARCHIVO DE FUNCIONES: funciones.lib *******/

<?php
require_once('configuracion.php');   /*variables bbdd, user y passw*/

function busqueda($nro_operacion)
{
    global $bbdd, $user, $passw;
    $id = ifx_connect($bbdd, $user, $passw);
    $sql = "select nro_operacion, cantidad, precio, nro_inv
                from tabla_correspondiente
                where nro_operacion=".$nro_operacion." and nro_item=1";
    $salida=ifx_query($sql, $id);
    while($fila=ifx_fetch_row($salida))
    {
        $cantidad = $fila["cantidad"];
        $precio = $fila["precio"];
        $nro_inv = $fila["nro_inv"];
    }
    $arrRespuesta['nro_operacion'] = $nro_operacion;
    $arrRespuesta['cantidad'] = $cantidad;
    $arrRespuesta['precio'] = $precio;
    $arrRespuesta['nro_inv'] = $nro_inv;

    return new soapval('return', 'tns:estructura', $arrRespuesta);
}
?>

/******** ARCHIVO CLIENTE: cliente7.php *******/

<form id="form1" name="form1" method="post" action="">
STTWEB - Devuelve array de datos
<br><br>
  <table width="23%" border="0" cellspacing="0" cellpadding="0">
    <tr>
      <td>Nro operacion: </td>
      <td><input name="nro_operacion" type="text" id="a" size="5" 
value="<?echo $nro_operacion;?>"></td>
    </tr>
    <tr>
      <td>&nbsp;</td>
      <td><input type="submit" name="button" id="button" value="Submit" 
/></td>
    </tr>
  </table>
</form>

<?
require_once('/usr/local/lib/nusoap/lib/nusoap.php');

if(isset($_POST['nro_operacion']) )
{
    $nro_operacion = $_POST['nro_operacion'];

    $serverURL='http://xxx.xxx.xxx.xxx/ws/servidor';
    $serverScript = 'servidor7.php';
    $metodoALlamar = 'busqueda';
    $cliente = new nusoap_client("$serverURL/$serverScript?wsdl", 'wsdl');

    $error = $cliente->getError();
    if ($error)
    {
        echo '<pre style="color: red">Error 0:' . $error . '</pre>';
        echo '<p style="color:red;'>htmlspecialchars($cliente->getDebug(), 
ENT_QUOTES).'</p>';
        die();
    }
    $parametros = array('nro_operacion'=> $nro_operacion);
    $resultado = $cliente->call($metodoALlamar, $parametros, 
"uri:$serverURL/$serverScript", 
"uri:$serverURL/$serverScript/$metodoALlamar");


    if (is_array($resultado))
    {
        echo "el resultado es un array<br>";
        if (empty($resultado))
            echo "Resultado vacio 1";
        else
            echo "Array con datos.";
    }
    else
    {
        echo "el resultado NO es un array";
    }
echo "<br>";

    // Verificacion que los parametros estan ok, y si lo estan. mostrar rta.
    if ($cliente->fault)
    {
        $error1 = $cliente->getError();
        echo 'Error 1: '.$error1.'<br><br>';
        //print_r($cliente->getDebug());
    }
    else
    {
        $error2 = $cliente->getError();
        if ($error2)
        {
            print_r($cliente->getDebug());
            echo '<b style="color: red">Error 2: ' . $error2 . '</b>';
        }
        else
        {
            if (empty($resultado))
                echo "Resultado vacio 2";
            else
            {
                echo "Ver datos";
            }
        }
    }
}

?>



__________ Información de ESET NOD32 Antivirus, versión de la base de firmas de virus 6421 (20110830) __________

ESET NOD32 Antivirus ha comprobado este mensaje.

http://www.eset.com
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.