Tema: Web Service
Ver Mensaje Individual
  #1 (permalink)  
Antiguo 01/04/2016, 11:22
HernanFrancco
 
Fecha de Ingreso: marzo-2016
Mensajes: 9
Antigüedad: 8 años, 1 mes
Puntos: 0
Web Service

Tengo un web service utilizando SOAP. Pero me regresa los datos en un arreglo y lo que necesito es regresarlos en XML o JSON.

Aquí mi codigo:

Server
Código PHP:
<?php
include('nusoap.php');
$server = new soap_server;
$server->configureWSDL('obtenerMunicipio''urn:obtenerMunicipio');          
$server->wsdl->addComplexType('municipio','complexType','struct','all','',
               array(
                        
'edo_id' => array('name' => 'edo_id''type' => 'xsd:string'),
                        
'mpio_clave' => array('name' => 'mpio_clave''type' => 'xsd:string'),
                        
'mpio_descripcion' => array('name' => 'mpio_descripcion''type' => 'xsd:string' ),                    
                        ));
                        
$server->register('obtenerMunicipio',
                  array(
'edo_id' => 'xsd:string'),
                  array(
'return'=>'tns:municipio'),
                  
'urn:obtenerMunicipio',
                  
'urn:obtenerMunicipio#municipio',
                  
'rpc',
                  
'encoded',
                  
'Este método devuelve un producto.');                            

function 
obtenerMunicipio($parametro){
    
$con = new mysqli("localhost","root","","directorio2");
    
$sql " SELECT mpio_clave, edo_id,mpio_descripcion FROM municipio WHERE edo_id = $parametro ";
    
$stmt $con->prepare($sql);
    
$stmt->execute();
    
$stmt->bind_result($col1,$col2,$col3);
    
$stmt->fetch();
    
$row[0] = $col1;
    
$row[1] = $col2;
    
$row[2] = $col3;
    return array(
'edo_id' => $row[0],'mpio_clave' => $row[1],'mpio_descripcion' => $row[2]);
    
    
}
// 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);    
?>
Client
Código PHP:
<?php    
require('lib/nusoap.php');

error_reporting(E_COMPILE_ERROR|E_ERROR|E_CORE_ERROR);
  
$l_oClient = new nusoap_client ('http://localhost/proyectos/Server.php?wsdl''wsdl');
$l_oProxy  $l_oClient->getProxy();

?>

<html>
<header>
</header>
<body>
<form name="consulta1" method="post" action="<?php $l_stResult $l_oProxy->obtenerMunicipio($_POST["codigo"]); ?>">
Codigo del estado:<input type="text" name="codigo" maxlength="4">
<input type="submit" value="Consultar">
</form>
</body>
</html>

<?php    

   
print '<h1>Municipio :</h1>'
           
'<br>Estado id: '  $l_stResult['edo_id']
           . 
'<br>Municipio clave: '   $l_stResult['mpio_clave']
           . 
'<br>Municipio descripcion: ' $l_stResult['mpio_descripcion'];
       
      
?>

WSDL
Código PHP:
<?php    
include('nusoap.php');

function 
principal($monto$nombre){
    
$wsdl="http://localhost/proyectos/producto.php?wsdl";
    
$client = new nusoap_client($wsdl'wsdl');
    
$param=array('monto' => $Monto,);
    
$response $client -> call($nombre$param);
    return 
$response;
}
 
 
?>