Ver Mensaje Individual
  #1 (permalink)  
Antiguo 30/07/2008, 02:25
a7o
 
Fecha de Ingreso: julio-2008
Mensajes: 8
Antigüedad: 15 años, 9 meses
Puntos: 0
SOAP, PHP sin nusoap

Hola!

Llevo un par de días peleando con unos ejemplos de PHP que usan un servicio web. Estos ejemplos provienen de la página de Zend.

El problema radica en que el cliente no consigue invocar a las funciones del servidor, pese a que se crea correctamente el SoapClient y se muestran correctamente las funciones con getFunctions(): visualizamos: array(2) { [0]=> string(30) "float getQuote(string $symbol)" [1]=> string(31) "string getPrice(string $symbol)" }. Es posible que el fichero no sea accesible desde otros ficheros por estar en una intranet, que requiere estar validado.

El error que da al llamar a la función es:
Fatal error: Uncaught SoapFault exception: [HTTP] Unauthorized in C:\Inetpub\wwwroot\XML_PHP\a7o1\client3.php:5 Stack trace: #0 [internal function]: SoapClient->__doRequest('<?xml version="...', 'http://virtual01...', 'urn:xmethods-de...', 1, 0) #1 [internal function]: SoapClient->__call('getPrice', Array) #2 C:\Inetpub\wwwroot\XML_PHP\a7o1\client3.php(5): SoapClient->getPrice('hola') #3 {main} thrown in C:\Inetpub\wwwroot\XML_PHP\a7o1\client3.php on line 5

El codigo que tengo es:

client3.php
Código PHP:
 <?php
  $client 
= new SoapClient("stockquote.wsdl");
  
var_dump($client->__getFunctions());
  echo 
"<br>resultado: ".$client->getQuote("ibm");
?>

server1.php

Código PHP:
<?php
class QuoteService {

private 
$quotes = array("ibm" => 198.42);

function 
getQuote($symbol) {
if (isset(
$this->quotes[$symbol])) {
return 
$this->quotes[$symbol];
} else {
throw new 
SoapFault("Server","Unknown Symbol '$symbol'.");
}
}

function 
getPrice($str) {
$result"dame el precio";
return 
$result;
}
}

ini_set("soap.wsdl_cache_enabled","0");

$server = new SoapServer("stockquote.wsdl");
$server->setClass("QuoteService");
echo 
"iniciamos handle";
$server->handle();
?>
y finalmente stockquote.wsdl

Código:
<?xml version="1.0" encoding="UTF-8"?>
<definitions 	xmlns:tns="http://virtual01/XML_PHP/a7o1/" 
			xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" 
			xmlns:xsd="http://www.w3.org/2001/XMLSchema" 
			xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" 
			xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" 
			xmlns="http://schemas.xmlsoap.org/wsdl/" 
			name="StockQuote" 
			targetNamespace="http://virtual01/XML_PHP/a7o1/">
	<message name="getQuoteRequest">
		<part name="symbol" type="xsd:string"/>
	</message>
	<message name="getQuoteResponse">
		<part name="result" type="xsd:float"/>
	</message>
	<message name="getPriceRequest">
		<part name="symbol" type="xsd:string"/>
	</message>
	<message name="getPriceResponse">
		<part name="result" type="xsd:string"/>
	</message>
	<portType name="StockQuotePortType">
		<operation name="getQuote">
			<input message="tns:getQuoteRequest"/>
			<output message="tns:getQuoteResponse"/>
		</operation>
	</portType>
	<portType name="StockPricePortType">
		<operation name="getPrice">
			<input message="tns:getPriceRequest"/>
			<output message="tns:getPriceResponse"/>
		</operation>
	</portType>
	<binding name="StockQuoteBinding" type="tns:StockQuotePortType">
		<soap:binding style="rpc" transport="http://schemas.xmlsoap.org/soap/http"/>
		<operation name="getQuote">
			<soap:operation soapAction="urn:xmethods-delayed-quotes#getQuote"/>
			<input>
				<soap:body use="encoded" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" namespace="http://virtual01/XML_PHP/a7o1/"/>
			</input>
			<output>
				<soap:body use="encoded" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" namespace="http://virtual01/XML_PHP/a7o1/"/>
			</output>
		</operation>
	</binding>
	<binding name="StockPriceBinding" type="tns:StockPricePortType">
		<soap:binding style="rpc" transport="http://schemas.xmlsoap.org/soap/http"/>
		<operation name="getPrice">
			<soap:operation soapAction="urn:xmethods-delayed-quotes#getPrice"/>
			<input>
				<soap:body use="encoded" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" namespace="http://virtual01/XML_PHP/a7o1/"/>
			</input>
			<output>
				<soap:body use="encoded" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" namespace="http://virtual01/XML_PHP/a7o1/"/>
			</output>
		</operation>
	</binding>
	<service name="StockQuoteService">
		<port name="StockQuotePort" binding="tns:StockQuoteBinding">
			<soap:address location="http://virtual01/XML_PHP/a7o1/server1.php"/>
		</port>
	</service>
	<service name="StockPriceService">
		<port name="StockPricePort" binding="tns:StockPriceBinding">
			<soap:address location="http://virtual01/XML_PHP/a7o1/server1.php"/>
		</port>
	</service>
</definitions>
Es una pregunta para nota. A ver si alguien puede ayudarme o darme una pista.

Salu2 y gracias.