Foros del Web » Programando para Internet » PHP »

Web Service

Estas en el tema de Web Service en el foro de PHP en Foros del Web. 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í ...
  #1 (permalink)  
Antiguo 01/04/2016, 11:22
 
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;
}
 
 
?>
  #2 (permalink)  
Antiguo 01/04/2016, 11:29
 
Fecha de Ingreso: enero-2009
Ubicación: Kandor
Mensajes: 209
Antigüedad: 15 años, 3 meses
Puntos: 11
Respuesta: Web Service

En tu server, cuando hagas return array(......); usa return json_encode(array(......)); eso te convertira el arreglo en json
  #3 (permalink)  
Antiguo 01/04/2016, 11:45
 
Fecha de Ingreso: marzo-2016
Mensajes: 9
Antigüedad: 8 años, 1 mes
Puntos: 0
Respuesta: Web Service

Gracias ya lo hice, pero al momento de correr el Client me marca:
Fatal error: Call to a member function obtenerMunicipio() on a non-object in C:\wamp\www\Proyectos\Client.php on line 17 Call Stack #TimeMemoryFunctionLocation 10.0008243720{main}( )..\Client.php:0
  #4 (permalink)  
Antiguo 01/04/2016, 12:03
 
Fecha de Ingreso: enero-2009
Ubicación: Kandor
Mensajes: 209
Antigüedad: 15 años, 3 meses
Puntos: 11
Respuesta: Web Service

Lo que te dice ahi es que $l_oProxy no es un objeto y por eso no tiene la funcion obtenerMunicipio, posiblemente sea nulo $l_oProxy, pero no se si debas mover configuracion de nusoap ya que no lo manejo

Etiquetas: html, mysql, select, service, sql
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 23:46.