Ver Mensaje Individual
  #1 (permalink)  
Antiguo 29/01/2012, 09:37
Sys_VUn
 
Fecha de Ingreso: septiembre-2009
Ubicación: DF
Mensajes: 20
Antigüedad: 14 años, 7 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