Ver Mensaje Individual
  #1 (permalink)  
Antiguo 17/01/2013, 07:50
toruk21
 
Fecha de Ingreso: enero-2013
Mensajes: 1
Antigüedad: 11 años, 3 meses
Puntos: 0
Array de array con nusoap php

Bueno gente, soy nuevo en el foro aunq lo leo bastante. Hoy me encuentro desarrollando un web service en php con nusoap, el problema que tengo es que al enviar un array de arrays lo recibo mal desde el cliente, les dejo los códigos:

server.php

<?php
//libreria de nusoap
require_once ('nusoap/lib/nusoap.php');

$miURL = 'http://localhost/webservice/';
$server = new soap_server();
$server->configureWSDL('Web Service de Pruebas', $miURL);
$server->wsdl->schemaTargetNamespace = $miURL;

$server->wsdl->addComplexType(
'array_php',
'complexType',
'struct',
'all',
'',
array(
'pk' => array('name' => 'pk', 'type' =>'xsd:int'),
'rol' => array('name' => 'rol', 'type' =>'xsd:string'),
'descripcion' => array('name' => 'descripcion', 'type' =>'xsd:string')
)
);

$server->wsdl->addComplexType(
'array_array',
'complexType',
'array',
'',
'SOAP-ENC:Array',
array(),
array(
array('ref' => 'SOAP-ENC:arrayType',
'wsdl:arrayType' => 'tns:array_php[]'
)
),
'tns:array_php'
);

$server->register('prueba', // method name
array(), // input parameters
array('return' => 'tns:array_array'), // output parameters
$miURL, // namespace
$miURL . '#prueba', // soapaction
'rpc', // style
'encoded', // use
'Get Specific array_php' // documentation
);

function prueba()
{
$con = mysql_connect('localhost', 'root', '1234');
mysql_selectdb('laboral', $con);

$sql = "SELECT * FROM roles";
$q = mysql_query($sql);

$item = array();
while($r = mysql_fetch_assoc($q)){
$item[] = $r;
}
return $item;

}


if( !isset($HTTP_RAW_POST_DATA) )
$HTTP_RAW_POST_DATA = file_get_contents( 'php://input' );

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


cliente.php

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

//lineas de configuracion
$serverURL = 'http://localhost/webservice/ws2.php?wsdl';

$cliente = new nusoap_client($serverURL);

//sí error de conexión:
$error = $cliente->getError();
if($error){
echo "<p> '.$error.' </p>";
echo '<p style="color:red;'>htmlspecialchars($cliente->getDebug(), ENT_QUOTES).'</p>';
die();
}

echo "<br/>";
$arreglo2 = $cliente->call('prueba');

echo "<br/>";
for( $i=0; $i<3; $i++ ){
print_r( $arreglo2[$i]['pk'] );
print_r( $arreglo2[$i]['rol'] );
print_r( $arreglo2[$i]['descripcion'] );
echo "<br/>";
}
?>

el problema esq no me está retornando el array de array :/, espero me puedan ayudar

gracias