![Antiguo](http://static.forosdelweb.com/fdwtheme/images/statusicon/post_old.gif)
22/07/2013, 07:47
|
| | Fecha de Ingreso: julio-2013
Mensajes: 3
Antigüedad: 11 años, 6 meses Puntos: 0 | |
Respuesta: web service con php y mysql o sql server para el servidor es este
include('lib/nusoap.php');
$server = new soap_server;
$server->configureWSDL('obtenerProducto', 'urn:obtenerProducto');
$server->wsdl->addComplexType('producto','complexType','struct', 'all','',
array(
'idProducto' => array('name' => 'idProducto', 'type' => 'xsd:string'),
'titulo' => array('name' => 'titulo', 'type' => 'xsd:string'),
'descripcion' => array('name' => 'descripcion', 'type' => 'xsd:string' ),
'precio' => array('name' => 'precio', 'type' => 'xsd:string' ),
));
$server->register('obtenerProducto',
array('idProducto' => 'xsd:int'),
array('return'=>'tns:producto'),
'urn:obtenerProducto',
'urn:obtenerProducto#producto',
'rpc',
'encoded',
'Este método devuelve un producto.');
function obtenerProducto(){
$con = new mysql("localhost:9999","root","1234","producto");
$sql = " SELECT idProducto, titulo, descripcion, precio FROM producto where idProducto = 1 ";
$stmt = $con->prepare($sql);
$stmt->execute();
$stmt->bind_result($col1,$col2,$col3,$col4);
$stmt->fetch();
$row[0] = $col1;
$row[1] = $col2;
$row[2] = $col3;
$row[3] = $col4;
return array('idProducto' => $row[0],'titulo' => $row[1],'descripcion' => $row[2],'precio' => $row[3]);
}
// 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);
y para el cliente es este
require('lib/nusoap.php');
$l_oClient = new soapclient('http://localhost:9999/WebService/servicio1.php?wsdl', 'wsdl');
$l_oProxy = $l_oClient->getProxy();
$parametro = $_GET['idProducto'];
$l_stResult = $l_oProxy->obtenerProducto($parametro);
print '<h1>Producto :</h1>'
. '<br>Id Producto: ' . $l_stResult['idProducto']
. '<br>Titulo : ' . $l_stResult['titulo']
. '<br>Descripcion ' . $l_stResult['descripcion']
. '<br>Precio ' . $l_stResult['precio'];
me esta mostrando el XML que genera el servidor sin datos de la consulta(con la consulta probada y la base de datos con información) |