server.php
Código HTML:
 <?php
//require_once('../mysql4/cn.php');
include_once('lib/nusoap.php');
$server = new soap_server;
// $server->configureWSDL('obtenerProductos', 'urn:obtenerProductos');  
 
$ns= "http://localhost:8080/prueba"; 
$server->configureWSDL("obtenerProductos",$ns);
$server->wsdl->schematargetnamespace=$ns;
 
 
$server->wsdl->addComplexType('RenglonProducto','complexType','struct','all','',
               array(
                        'Codigo'            => array('name' => 'Codigo', 'type' => 'xsd:string'),
                        'Nombre'            => array('name' => 'Nombre', 'type' => 'xsd:string'),
                        'Descripcion'       => array('name' => 'Descripcion', 'type' => 'xsd:string' ),
                        'Precio'             => array('name' => 'Precio', 'type' => 'xsd:string' ),
                        ));
                        
$server->wsdl->addComplexType('ArrayOfRenglonProducto','complexType','array','','SOAP-ENC:Array',
                                array(),
                                array(        
                                            array('ref' => 'SOAP-ENC:arrayType',
                                                  'wsdl:arrayType' => 'tns:RenglonProducto[]'                              
                                                  )                                       
                                    ),
                                'tns:RenglonProducto');  
                      
 
//function obtenerProductos($id=false){
function obtenerProductos($id){
$con = new mysqli("localhost","root","","productos");
$sql = "select idProducto, titulo, descripcion, precio from producto";
//$link = ConectarBase();
//$rs = ConsultarBase($link,$sql);
//$rs = mysql_db_query($con,$sql);
$rs=$con->query($sql);
$n=0;
while($row = $rs->fetch_array(MYSQLI_NUM)) { 
 
    $html[$n]['Codigo']          =$row[0];
    $html[$n]['Nombre']          =$row[1];
    $html[$n]['Descripcion']     =$row[2];
    $html[$n]['Precio']           =$row[3];
    $n++; 
    // $rows[] = $html;
 
}
//echo $html[0]['Codigo']; 
return $html;
 
}
$server->xml_encoding = "utf-8";
$server->soap_defencoding = "utf-8";
$server->register('obtenerProductos',
                  array('Codigo' => 'xsd:string'),
                  array('return'=>'tns:ArrayOfRenglonProducto'),
                  $ns 
                  // 'urn:Servicio',
                  // 'urn:Servicio#obtenerProductos',
                  // 'rpc',
                  // 'literal',
                  // 'Este método devuelve la lista de  productos.'
                  );    
                  
// 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);    
?> 
 Cita:   
agradeceria su ayuda.. :) <?php    
// incluyo nusoap
include_once('lib/nusoap.php');
 
$l_oClient = new nusoap_client('http://localhost:8080/prueba/server.php?wsdl', 'wsdl');
//$l_oClient = new nusoap_client('http://localhost:8080/prueba/server.php?);
$err = $l_oClient->getError();
if ($err) {
echo '<h2>Constructor error</h2><pre>' . $err . '</pre>';
}
$l_oProxy = $l_oClient->getProxy();
 
 
// llama al webmethod (obtenerProducto)
$parametro = isset($_GET['idProducto'])?$_GET['idProducto']:"1";
$parras = array("sCodigo" => $parametro );
//$parametro ='1';
//$l_stResult = $l_oProxy->obtenerProductos($parametro);
$l_stResult = $l_oProxy->obtenerProductos("1");
//$l_stResult = $l_oClient->call('obtenerProductos',"1");
//$l_stResult = $l_oClient->call('obtenerProductos',$parras);
//print('<pre>');
print_r($l_stResult);
// print('</pre>');
 
print_r($l_stResult[0]['Codigo']);
echo $l_stResult;
// $array=$html;
var_dump($l_stResult);
 
$cadena = '';
$cadena .='<?xml version="1.0" encoding="utf-8"?><productos>
<producto>';
 
if (count($l_stResult)>1)
{
echo count($l_stResult);
echo "sssi hay";
$i=0;
 
foreach($l_stResult as $row=>$lu1){
 
echo $row."-".$lu1;
/*
$cadena .=' <codigo>'.$row['Codigo'].'</codigo>
<nombre>'.$row['Nombre'].'</nombre>
<descripcion>'.$row['Descripcion'].'</descripcion>
<precio><![CDATA['.$row['Precio'].']]></precio>';
 
*/
 
}
 
}
else
{
 
echo"<p>There's nothing in the array.....</p>";
}
 
 
$cadena .=' </producto>
</productos>';
 
//print($cadena);
 
?>
 // incluyo nusoap
include_once('lib/nusoap.php');
$l_oClient = new nusoap_client('http://localhost:8080/prueba/server.php?wsdl', 'wsdl');
//$l_oClient = new nusoap_client('http://localhost:8080/prueba/server.php?);
$err = $l_oClient->getError();
if ($err) {
echo '<h2>Constructor error</h2><pre>' . $err . '</pre>';
}
$l_oProxy = $l_oClient->getProxy();
// llama al webmethod (obtenerProducto)
$parametro = isset($_GET['idProducto'])?$_GET['idProducto']:"1";
$parras = array("sCodigo" => $parametro );
//$parametro ='1';
//$l_stResult = $l_oProxy->obtenerProductos($parametro);
$l_stResult = $l_oProxy->obtenerProductos("1");
//$l_stResult = $l_oClient->call('obtenerProductos',"1");
//$l_stResult = $l_oClient->call('obtenerProductos',$parras);
//print('<pre>');
print_r($l_stResult);
// print('</pre>');
print_r($l_stResult[0]['Codigo']);
echo $l_stResult;
// $array=$html;
var_dump($l_stResult);
$cadena = '';
$cadena .='<?xml version="1.0" encoding="utf-8"?><productos>
<producto>';
if (count($l_stResult)>1)
{
echo count($l_stResult);
echo "sssi hay";
$i=0;
foreach($l_stResult as $row=>$lu1){
echo $row."-".$lu1;
/*
$cadena .=' <codigo>'.$row['Codigo'].'</codigo>
<nombre>'.$row['Nombre'].'</nombre>
<descripcion>'.$row['Descripcion'].'</descripcion>
<precio><![CDATA['.$row['Precio'].']]></precio>';
*/
}
}
else
{
echo"<p>There's nothing in the array.....</p>";
}
$cadena .=' </producto>
</productos>';
//print($cadena);
?>
 

