Ver Mensaje Individual
  #2 (permalink)  
Antiguo 27/01/2012, 16:38
TheM4ster
 
Fecha de Ingreso: julio-2007
Mensajes: 109
Antigüedad: 16 años, 9 meses
Puntos: 1
Respuesta: WebService Nusoap php mysql

gente, ya resolvi el problema, logre imprimir los resultados en el cliente.php, les dejo el codigo para los q se topan con este problema,

server.php
Código PHP:
Ver original
  1. <?php
  2. require_once('../mysql4/cn.php');
  3. include('../lib/nusoap.php');
  4. $server = new soap_server;
  5. // $server->configureWSDL('obtenerProductos', 'urn:obtenerProductos');  
  6.  
  7. $ns     = "http://localhost/ws/mysql3/";
  8. $server->configureWSDL("obtenerProductos",$ns);
  9. $server->wsdl->schematargetnamespace=$ns;
  10.  
  11.  
  12. $server->wsdl->addComplexType('RenglonProducto','complexType','struct','all','',
  13.                array(
  14.                         'Codigo'            => array('name' => 'Codigo', 'type' => 'xsd:string'),
  15.                         'Nombre'            => array('name' => 'Nombre', 'type' => 'xsd:string'),
  16.                         'Descripcion'       => array('name' => 'Descripcion', 'type' => 'xsd:string' ),
  17.                         'Stock'             => array('name' => 'Stock', 'type' => 'xsd:string' ),
  18.                         ));
  19.                        
  20. $server->wsdl->addComplexType('ArrayOfRenglonProducto','complexType','array','','SOAP-ENC:Array',
  21.                                 array(),
  22.                                 array(        
  23.                                             array('ref' => 'SOAP-ENC:arrayType',
  24.                                                   'wsdl:arrayType' => 'tns:RenglonProducto[]'                              
  25.                                                   )                                      
  26.                                     ),
  27.                                 'tns:RenglonProducto');                        
  28.  
  29. function obtenerProductos($id=false){
  30.  
  31. $sql = "SELECT ID_PRODUCTO, NOM_PRODUCTO, DES_PRODUCTO, STOCK FROM tab_producto order by ID_PRODUCTO";
  32. $link = ConectarBase();
  33. $rs = ConsultarBase($link,$sql);
  34. $n=0;
  35. while ($row = mysql_fetch_array($rs)) {
  36.  
  37.     $html[$n]['Codigo']          =$row[0];
  38.     $html[$n]['Nombre']          =$row[1];
  39.     $html[$n]['Descripcion']     =$row[2];
  40.     $html[$n]['Stock']           =$row[3];
  41.     $n++;
  42.     // $rows[] = $html;
  43. }
  44.  
  45. return $html;
  46.  
  47. }
  48.  
  49. $server->xml_encoding = "utf-8";
  50. $server->soap_defencoding = "utf-8";
  51. $server->register('obtenerProductos',
  52.                   array('Codigo' => 'xsd:int'),
  53.                   array('return'=>'tns:ArrayOfRenglonProducto'),
  54.                   $ns
  55.                   // 'urn:Servicio',
  56.                   // 'urn:Servicio#obtenerProductos',
  57.                   // 'rpc',
  58.                   // 'literal',
  59.                   // 'Este método devuelve la lista de  productos.'
  60.                   );    
  61.                  
  62. // Use the request to (try to) invoke the service
  63. $HTTP_RAW_POST_DATA = isset($HTTP_RAW_POST_DATA) ? $HTTP_RAW_POST_DATA : '';
  64. $server->service($HTTP_RAW_POST_DATA);    
  65. ?>

cliente.php
Código PHP:
Ver original
  1. <?php    
  2. // incluyo nusoap
  3. require('../lib/nusoap.php');
  4.  
  5. $l_oClient = new nusoap_client('http://localhost/ws/mysql3/server.php?wsdl', 'wsdl');
  6. $l_oProxy  = $l_oClient->getProxy();
  7.        
  8. // llama al webmethod (obtenerProducto)
  9. $parametro = isset($_GET['idProducto'])?$_GET['idProducto']:'';
  10. $l_stResult = $l_oProxy->obtenerProductos($parametro);  
  11. // print('<pre>');
  12. // print_r($l_stResult);
  13. // print('</pre>');
  14.  
  15. $cadena = '';
  16. $cadena .='<?xml version="1.0" encoding="utf-8"?><productos>
  17.         <producto>';
  18. foreach($l_stResult as $row){
  19. $cadena .=' <codigo>'.$row['Codigo'].'</codigo>
  20.             <nombre>'.$row['Nombre'].'</nombre>
  21.             <descripcion>'.$row['Descripcion'].'</descripcion>
  22.             <stock><![CDATA['.$row['Stock'].']]></stock>';
  23. }  
  24. $cadena .=' </producto>
  25.             </productos>';
  26.            
  27. print($cadena);
  28.  
  29.  ?>

Saludos,