Ver Mensaje Individual
  #12 (permalink)  
Antiguo 17/04/2012, 01:26
julianrb90
 
Fecha de Ingreso: marzo-2012
Mensajes: 21
Antigüedad: 12 años, 1 mes
Puntos: 1
Respuesta: Web service php para obtencion de datos de la base de datos postgresql

Cita:
Iniciado por GatorV Ver Mensaje
El XML se ve bien pero es complicado ver que parte falla, te recomiendo uses una herramienta como [URL="http://www.soapui.org/"]SoapUI[/URL] para verificar que todo esta correcto en tu web service y ya luego te puedas mover a la parte del cliente.

Saludos.
Modifique los codigo y siguen apareciendo los siguientes errores:
Cita:
PHP Warning: pg_query() [<a href='function.pg-query'>function.pg-query</a>]: Query failed: ERROR: error de sintaxis al final de la entrada\nLINE 1: ...titulo, descripcion, precio from producto where id_producto=\n ^ in C:\\Program Files (x86)\\Apache Software Foundation\\Apache2.2\\htdocs\\Prueba\\ws.php on line 6
PHP Warning: pg_num_rows() expects parameter 1 to be resource, boolean given in C:\\Program Files (x86)\\Apache Software Foundation\\Apache2.2\\htdocs\\Prueba\\ws.php on line 7
PHP Notice: Undefined variable: respuesta in C:\\Program Files (x86)\\Apache Software Foundation\\Apache2.2\\htdocs\\Prueba\\ws.php on line 15
ademas algunas veces sale el error o supongo que los anteriores se deben a este:

Cita:
PHP Notice: Undefined index: idproduc in C:\\Program Files (x86)\\Apache Software Foundation\\Apache2.2\\htdocs\\Prueba\\cliente.php on line 4, referer: http://localhost:9090/Prueba/index.php
Aqui estan los codigo:

ws.php
Código PHP:
<?php
require_once('lib/nusoap.php');
function 
obtenerProducto($id){
    
$con=pg_connect("host=localhost dbname=prueba user=admin password=123" ) or die("Error en la conexion a la base de datos");
    
$sql="select id_producto, titulo, descripcion, precio from producto where id_producto=".$id."";
    
$busqueda=pg_query($con,$sql) ;    
    if(
pg_num_rows($busqueda)!=0){
        while( 
$row pg_fetch_object $busqueda)) {    
            
$respuesta=array('id_producto' => $row->id_producto,
            
'titulo' => $row->titulo,
            
'descripcion' => $row->descripcion,
            
'precio' => $row->precio);
        }
    }
    return new 
soapval('return''tns:producto'$respuesta);
}
$server = new soap_server();
$miURL='http://localhost:9090/Prueba';
$server->configureWSDL('obtenerProducto'$miURL);   
$server->wsdl->schemaTargetNamespace=$miURL;       
$server->wsdl->addComplexType('producto','complexType','struct','all','',
               array(
'id_producto' => array('name' => 'id_producto''type' => 'xsd:int'),
                     
'titulo' => array('name' => 'titulo''type' => 'xsd:string'),
                     
'descripcion' => array('name' => 'descripcion''type' => 'xsd:string' ),
                     
'precio' => array('name' => 'precio''type' => 'xsd:int' ),
                     ));                      
$server->register('obtenerProducto',
                  array(
'id_producto' => 'xsd:int'),
                  array(
'return'=>'tns:producto'),
                  
$miURL);                            

// Use the request to (try to) invoke the service
if (isset($HTTP_RAW_POST_DATA))
{
    
$input $HTTP_RAW_POST_DATA;
}
else
{
    
$input implode("\r\n"file('php://input'));
}
$server->service($input);
exit;
?>
cliente.php

Código PHP:
<?php  
ini_set
('soap.wsdl_cache_enabled''0'); 
require_once(
'lib/nusoap.php'); 
$parametro=$_POST['idproduc'];
echo 
$parametro;
$l_oClient = new soapclient('http://localhost:9090/Prueba/ws.php?wsdl','wsdl');
$err $l_oClient->getError();
if (
$err) {
    
// Display the error
    
echo '<p><b>Constructor error: ' $err '</b></p>';
    
// At this point, you know the call that follows will fail
}
$metodoALlamar 'obtenerProducto';   
$l_stResult $l_oClient->call(
                
$metodoALlamar,
                array(
'id' => $parametro),
                
"http://localhost:9090/Prueba",
                
"http://localhost:9090/Prueba/ws.php/$metodoALlamar");     
// Verificacion que los parametros estan ok, y si lo estan. mostrar rta.
if ($l_oClient->fault) {
 echo 
'<b>Error: ';
 
print_r($l_stResult);
 echo 
'</b>';
} else {
 
$error $l_oClient->getError();
 if (
$error) {
 echo 
'<b style="color: red">Error: ' $error '</b>';
 } else {
 print 
'<h1>Producto :</h1>'
           
'<br>Id Producto: '  $l_stResult['id_producto']
           . 
'<br>Titulo : '   $l_stResult['titulo']
           . 
'<br>Descripcion ' $l_stResult['descripcion']
           . 
'<br>Precio ' $l_stResult['precio'];
echo 
'<h2>Request</h2>';
echo 
'<pre>' htmlspecialchars($l_oClient->requestENT_QUOTES) . '</pre>';
echo 
'<h2>Response</h2>';
echo 
'<pre>' htmlspecialchars($l_oClient->responseENT_QUOTES) . '</pre>';
echo 
'<h2>Debug</h2>';
echo 
'<pre>' htmlspecialchars($l_oClient->debug_strENT_QUOTES) . '</pre>';
 }
}   
?>
index.php
Código PHP:
<html>
    <
head>
        <
title>Prueba</title>
        <
Script languaje="javascript">
            function 
validarFormulario(formulario){
                
error=false
                
if(!error&&formulario.idproduc.value==""){
                    
alert('El UserId es obligatorio')
                    
formulario.idproduc.focus()
                    
error=true    
                
}
                return !
error
            
}
        
</script>
    </head>
    <body>
        <center>
        <form name="confirmarpar" action="cliente.php" method="POST">
            <table>
                <tr>
                    <td>UserID</td>
                    <td><input type="text" name="idproduc" size="20" maxlength="20"/></td>
    
                </tr>    
                <tr>
                    <td><input type="submit" name="enviar" value="Enviar"  onClick="return validarFormulario(confirmarpar)"/></td>
                    <td><input type="reset" name="borrar" value="Borrar"/></td>
                </tr>    
            </table>

        </form>
        </center>        
    </body>
    
</html>