Foros del Web » Programando para Internet » PHP »

Web Service desde php con mysql

Estas en el tema de Web Service desde php con mysql en el foro de PHP en Foros del Web. Saludos amigos, Necesito desarrollar una aplicación que integre php,mysql y ws. A manera de ejemplo tome el código indicado por stone_neo en el sguiente enlace:http://www.forosdelweb.com/f18/como-hacer-web-service-con-datos-complejos-php-mysql-630862/ ...
  #1 (permalink)  
Antiguo 29/01/2012, 09:37
 
Fecha de Ingreso: septiembre-2009
Ubicación: DF
Mensajes: 20
Antigüedad: 14 años, 6 meses
Puntos: 0
Web Service desde php con mysql

Saludos amigos,
Necesito desarrollar una aplicación que integre php,mysql y ws. A manera de ejemplo tome el código indicado por stone_neo en el sguiente enlace:http://www.forosdelweb.com/f18/como-hacer-web-service-con-datos-complejos-php-mysql-630862/

Código PHP:
<?php
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($id){
$con = new mysqli("localhost","user","pass","productos");
$sql = " SELECT idProducto, titulo, descripcion, precio FROM producto where idProducto = $id ";
$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);
?>

El Cliente :


Código PHP:
<?php
require('lib/nusoap.php');

$l_oClient = new soapclient('http://localhost/ws/ws.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'];

?>

Y al invocarlo desde mi sitio:http://localhost/proyecto/nusoap/cliente.php no muestra nada y al hacerle var_dump($l_oClient) obtengo lo siguiente:

object(nusoap_client)#2 (49) { ["username"]=> string(0) "" ["password"]=> string(0) "" ["authtype"]=> string(0) "" ["certRequest"]=> array(0) { } ["requestHeaders"]=> bool(false) ["responseHeaders"]=> string(0) "" ["responseHeader"]=> NULL ["document"]=> string(0) "" ["endpoint"]=> string(44) "http://localhost/proyecto/nusoap/ws.php?wsdl" ["forceEndpoint"]=> string(0) "" ["proxyhost"]=> bool(false) ["proxyport"]=> bool(false) ["proxyusername"]=> bool(false) ["proxypassword"]=> bool(false) ["xml_encoding"]=> string(0) "" ["http_encoding"]=> bool(false) ["timeout"]=> int(0) ["response_timeout"]=> int(30) ["endpointType"]=> string(4) "wsdl" ["persistentConnection"]=> bool(false) ["defaultRpcParams"]=> bool(false) ["request"]=> string(0) "" ["response"]=> string(0) "" ["responseData"]=> string(0) "" ["cookies"]=> array(0) { } ["decode_utf8"]=> bool(true) ["operations"]=> array(0) { } ["curl_options"]=> array(0) { } ["bindingType"]=> string(0) "" ["use_curl"]=> bool(false) ["fault"]=> NULL ["faultcode"]=> NULL ["faultstring"]=> NULL ["faultdetail"]=> NULL ["title"]=> string(6) "NuSOAP" ["version"]=> string(5) "0.7.3" ["revision"]=> string(18) "$Revision: 1.114 $" ["error_str"]=> string(0) "" ["debug_str"]=> string(276) "2012-01-29 15:12:32.546883 nusoap_client: ctor wsdl=1 timeout=0 response_timeout=30 endpoint=string(44) "http://localhost/proyecto/nusoap/ws.php?wsdl" 2012-01-29 15:12:32.576812 nusoap_client: will use lazy evaluation of wsdl from http://localhost/proyecto/nusoap/ws.php?wsdl " ["charencoding"]=> bool(true) ["debugLevel"]=> int(9) ["XMLSchemaVersion"]=> string(32) "http://www.w3.org/2001/XMLSchema" ["soap_defencoding"]=> string(10) "ISO-8859-1" ["namespaces"]=> array(4) { ["SOAP-ENV"]=> string(41) "http://schemas.xmlsoap.org/soap/envelope/" ["xsd"]=> string(32) "http://www.w3.org/2001/XMLSchema" ["xsi"]=> string(41) "http://www.w3.org/2001/XMLSchema-instance" ["SOAP-ENC"]=> string(41) "http://schemas.xmlsoap.org/soap/encoding/" } ["usedNamespaces"]=> array(0) { } ["typemap"]=> array(6) { ["http://www.w3.org/2001/XMLSchema"]=> array(43) { ["string"]=> string(6) "string" ["boolean"]=> string(7) "boolean" ["float"]=> string(6) "double" ["double"]=> string(6) "double" ["decimal"]=> string(6) "double" ["duration"]=> string(0) "" ["dateTime"]=> string(6) "string" ["time"]=> string(6) "string" ["date"]=> string(6) "string" ["gYearMonth"]=> string(0) "" ["gYear"]=> string(0) "" ["gMonthDay"]=> string(0) "" ["gDay"]=> string(0) "" ["gMonth"]=> string(0) "" ["hexBinary"]=> string(6) "string" ["base64Binary"]=> string(6) "string" ["anyType"]=> string(6) "string" ["anySimpleType"]=> string(6) "string" ["normalizedString"]=> string(6) "string" ["token"]=> string(6) "string" ["language"]=> string(0) "" ["NMTOKEN"]=> string(0) "" ["NMTOKENS"]=> string(0) "" ["Name"]=> string(0) "" ["NCName"]=> string(0) "" ["ID"]=> string(0) "" ["IDREF"]=> string(0) "" ["IDREFS"]=> string(0) "" ["ENTITY"]=> string(0) "" ["ENTITIES"]=> string(0) "" ["integer"]=> string(7) "integer" ["nonPositiveInteger"]=> string(7) "integer" ["negativeInteger"]=> string(7) "integer" ["long"]=> string(7) "integer" ["int"]=> string(7) "integer" ["short"]=> string(7) "integer" ["byte"]=> string(7) "integer" ["nonNegativeInteger"]=> string(7) "integer" ["unsignedLong"]=> string(0) "" ["unsignedInt"]=> string(0) "" ["unsignedShort"]=> string(0) "" ["unsignedByte"]=> string(0) "" ["positiveInteger"]=> string(0) "" } ["http://www.w3.org/2000/10/XMLSchema"]=> array(11) { ["i4"]=> string(0) "" ["int"]=> string(7) "integer" ["boolean"]=> string(7) "boolean" ["string"]=> string(6) "string" ["double"]=> string(6) "double" ["float"]=> string(6) "double" ["dateTime"]=> string(6) "string" ["timeInstant"]=> string(6) "string" ["base64Binary"]=> string(6) "string" ["base64"]=> string(6) "string" ["ur-type"]=> string(5) "array" } ["http://www.w3.org/1999/XMLSchema"]=> array(11) { ["i4"]=> string(0) "" ["int"]=> string(7) "integer" ["boolean"]=> string(7) "boolean" ["string"]=> string(6) "string" ["double"]=> string(6) "double" ["float"]=> string(6) "double" ["dateTime"]=> string(6) "string" ["timeInstant"]=> string(6) "string" ["base64Binary"]=> string(6) "string" ["base64"]=> string(6) "string" ["ur-type"]=> string(5) "array" } ["http://soapinterop.org/xsd"]=> array(1) { ["SOAPStruct"]=> string(6) "struct" } ["http://schemas.xmlsoap.org/soap/encoding/"]=> array(3) { ["base64"]=> string(6) "string" ["array"]=> string(5) "array" ["Array"]=> string(5) "array" } ["http://xml.apache.org/xml-soap"]=> array(1) { [0]=> string(3) "Map" } } ["xmlEntities"]=> array(5) { ["quot"]=> string(1) """ ["amp"]=> string(1) "&" ["lt"]=> string(1) "<" ["gt"]=> string(1) ">" ["apos"]=> string(1) "'" } ["wsdlFile"]=> string(44) "http://localhost/proyecto/nusoap/ws.php?wsdl" ["wsdl"]=> NULL }

Estoy utilizando AppServ en Windows XP. Cree la BD con sus respectivos campos y los datos de acceso son los correctos,

Alguien podría ayudarme por favor?. Gracias
  #2 (permalink)  
Antiguo 29/01/2012, 14:20
 
Fecha de Ingreso: julio-2007
Mensajes: 109
Antigüedad: 16 años, 9 meses
Puntos: 1
Respuesta: Web Service desde php con mysql

@Sys_VUn hola man,
No entiendo cual es tu problema,
  #3 (permalink)  
Antiguo 29/01/2012, 15:34
 
Fecha de Ingreso: septiembre-2009
Ubicación: DF
Mensajes: 20
Antigüedad: 14 años, 6 meses
Puntos: 0
Respuesta: Web Service desde php con mysql

Hola TheM4ster,
Necesito hacer una aplicación con php que me entregue datos desde mysql a través del servicio web, por lo que tengo mi cliente, servidor y la base de datos. Trato de consumir el servicio en el cliente para traerme los campos requeridos como Id Producto,Titulo, etc. lo cual no me está funcionando al ver el resultado de var_dump($l_oClient). Sabes cual es el error? o como alguna forma de hacer todo esto? Gracias man
  #4 (permalink)  
Antiguo 29/01/2012, 16:59
 
Fecha de Ingreso: julio-2007
Mensajes: 109
Antigüedad: 16 años, 9 meses
Puntos: 1
Respuesta: Web Service desde php con mysql

El problema esta en la asignación de los valores al array,
de todas maneras, este tema ya lo vi y lo resolvi,
te dejo el link, para que lo rebizes

http://www.forosdelweb.com/f18/webse...-mysql-972099/

y haber si opinas y dejas un comentario, acerca de los xmls.

Saludos,
  #5 (permalink)  
Antiguo 29/01/2012, 18:49
 
Fecha de Ingreso: septiembre-2009
Ubicación: DF
Mensajes: 20
Antigüedad: 14 años, 6 meses
Puntos: 0
Respuesta: Web Service desde php con mysql

Gracias TheM4ster por toda la ayuda, sin embargo aún no logro imprimir el resultado en el cliente.Seguí su código exactamente incluyendo la base de datos. Como dato adicional estoy utilizando AppServ bajo WinXP.
Por otro lado, el servicio web responde correctamente en: http://localhost/proyecto/nusoap/ws.php?wsdl. Al hacerle var_dump a la variable $l_oClient me vuelve a mostar el mensaje indicado anterior object(nusoap_client)#2 (49) { ["username"]=> string(0) "" ["password"]=> string(0) "" ["authtype"]=> string(0) "" ["certRequest"]=> array(0) { } ["requestHeaders"]=> bool(false) ["responseHeaders"]=> string(0) "" ["responseHeader"]=> NULL ["document"]=> string(0) "".... Alguna idea adicional man?
saludos,
  #6 (permalink)  
Antiguo 30/01/2012, 09:47
 
Fecha de Ingreso: julio-2007
Mensajes: 109
Antigüedad: 16 años, 9 meses
Puntos: 1
Respuesta: Web Service desde php con mysql

Hola, pero esta bien, el formato de salida de la funcion var_dump(), es de esa manera,
si quieres imprimir el array completo con sus indices y valores, de manera ordenada, te recomiendo que lo hagas asi,

print('<pre>');
print_r($l_stResult);
print('</pre>');

y de dato extra, estoy utilizando la libreria : nusoap-0.9.5

Saludos,
  #7 (permalink)  
Antiguo 05/02/2012, 10:17
 
Fecha de Ingreso: septiembre-2009
Ubicación: DF
Mensajes: 20
Antigüedad: 14 años, 6 meses
Puntos: 0
Respuesta: Web Service desde php con mysql

Hola TheM4ster, gracias hermano por tu tiempo. Resolví el problema cambiando localhost por 127.0.0.1 del lado del cliente, quedando el código así:

Código PHP:
<?php
require('lib/nusoap.php');

$l_oClient = new soapclient('http://127.0.0.1/ws/ws.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'];

?>
Saludos.

Etiquetas: mysql, 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 08:37.