PHP - Web Service

 
Vista:

Web Service

Publicado por Hernan (1 intervención) el 01/04/2016 23:36:20
Hola, estoy realizando un web service SOAP. Tengo el Cliente & Servidor, pero me devuelve los datos en un arreglo, y necesito que los devuelva en XML o Json.

Server
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
<?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
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
<?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'];
 
 
?>
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder

Web Service

Publicado por uyi (1 intervención) el 12/04/2016 18:25:45
Hola, estoy realizando un web service SOAP. Tengo el Cliente & Servidor, pero me devuelve los datos en un arreglo, y necesito que los devuelva en XML o Json.
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar