我正在尝试设置一个没有wsdl的web服务(目前),但没有工作。
我有一个名为“Operaciones.php”的文件,代码如下:
<?php namespace ClasesT6; use PDO, PDOException; class Operaciones extends Conexion { public function __construct() { parent::__construct(); } function getPVP($id) { $pvp = null; $consulta = " SELECT pvp FROM productos WHERE id='$id' "; $stmt = $this->conexion->prepare($consulta); try { $stmt->execute(); if($stmt) { $row = $stmt->fetch(); $pvp = $row['pvp']; } } catch (PDOException $ex) { die("Error al recuperar el pvp del producto indicado: " . $ex->getMessage()); } return $pvp; } function getStock($idproducto, $idtienda) { $stock = null; $consulta = " SELECT unidades FROM stocks WHERE producto='$idproducto' AND tienda='$idtienda' "; $stmt = $this->conexion->prepare($consulta); try { $stmt->execute(); if($stmt) { $row = $stmt->fetch(); $stock = $row['unidades']; } } catch (PDOException $ex) { die("Error al recuperar el stock del producto indicado en la tienda indicada: " . $ex->getMessage()); } return $stock; } function getFamilias() { $familiasCod = array(); $consulta = " SELECT * FROM familias "; $stmt = $this->conexion->prepare($consulta); try { $stmt->execute(); if($stmt) { $row = $stmt->fetch(); while ($row != null) { $familiasCod[] = "{$row['cod']}"; $row = $stmt->fetch(); } } } catch (PDOException $ex) { die("Error al recuperar el código de las familias: " . $ex->getMessage()); } return $familiasCod; } function getProductosFamilia($cod) { $productosFamiliaIds = array(); $consulta = " SELECT id FROM productos WHERE familia='".$cod."' "; $stmt = $this->conexion->prepare($consulta); try { $stmt->execute(); if($stmt) { $row = $stmt->fetch(); while ($row != null) { $productosFamiliaIds[] = "{$row['id']}"; $row = $stmt->fetch(); } } } catch (PDOException $ex) { die("Error al recuperar el id de los productos de la familia indicada: " . $ex->getMessage()); } return $productosFamiliaIds; } } ?>
然后我得到了文件“service.php”,代码如下:
<?php require '../vendor/autoload.php'; $uri = 'http://localhost/archivos/FP/DWES/tarea6/servidorSoap'; $parametros = ['uri'=>$uri]; try { $server = new SoapServer(NULL, $parametros); $server->setClass('Operaciones'); $server->handle(); } catch (SoapFault $f) { die("error en server: " . $f->getMessage()); } ?>
然后我得到了文件“cliente.php”,其中包含以下代码:
<?php require '../vendor/autoload.php'; $url = 'http://localhost/archivos/FP/DWES/tarea6/servidorSoap/servicio.php'; $uri = 'http://localhost/archivos/FP/DWES/tarea6/servidorSoap'; header('Content-Type: text/html; charset=UTF-8'); try { $cliente = new SoapClient(null, ['location' => $url, 'uri' => $uri, 'trace'=>true]); } catch (SoapFault $ex) { echo "Error: ".$ex->getMessage(); } $paramPVP = ['id' => "1"]; $getPVP = $cliente->__soapCall('getPVP', $paramPVP); ?>
当我在本地主机上打开client.php时,会出现以下错误:
致命错误:未捕获SoapFault异常:[Applications/XAMPP/xampfiles/htdocs/files/FP/DWES/task6/public/client.php中不存在[SOAP-ENV:Server]函数'getPVP'(17):SoapClient->__soapCall('getPVP',Array)#1{main}在第17行的/Applications/XAMPP/xampfiles/htdocs/archivos/FP/DWES/tarea6/public/client.php中抛出
我已经按照课程中的说明制作了service.php和client.php,但它不起作用,我不知道如何修复它。
非常感谢您提出的解决方案建议