Kotofeich
Новичок
Простейший soap сервер и клиент
Второй день бьюсь, не могу понять ошибку.
Пытаюсь сделать простейший soap сервер с wsdl и клиент к нему.
Вот код сервера:
файл stockquote1.php
wsdl-документ (stockquote1.wsdl)
Причем в wsdl-коде eclipse почему-то ругается на строчки
<input message='tns:getQuoteRequest'/>
<output message='tns:getQuoteResponse'/>
И вот код клиента (client.php):
В итоге при запуске клиента получаю ошибку
Помогите пожалуйста.
P.S. Или покажите код примитивного рабочего сервера на soap.
Второй день бьюсь, не могу понять ошибку.
Пытаюсь сделать простейший soap сервер с wsdl и клиент к нему.
Вот код сервера:
файл stockquote1.php
PHP:
<?php
$quotes = array(
"ibm" => 98.42
);
function getQuote($symbol) {
global $quotes;
return $quotes[$symbol];
}
ini_set("soap.wsdl_cache_enabled", "0"); // отключаем кэширование WSDL
$server = new SoapServer("stockquote1.wsdl");
$server->addFunction("getQuote");
$server->handle();
?>
PHP:
<?xml version ='1.0' encoding ='UTF-8' ?>
<definitions name='StockQuote'
targetNamespace='StockQuote'
xmlns:tns=' [url]http://example.org/StockQuote[/url] '
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/'>
<message name='getQuoteRequest'>
<part name='symbol' type='xsd:string'/>
</message>
<message name='getQuoteResponse'>
<part name='Result' type='xsd:float'/>
</message>
<portType name='StockQuotePortType'>
<operation name='getQuote'>
<input message='tns:getQuoteRequest'/>
<output message='tns:getQuoteResponse'/>
</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' namespace='urn:xmethods-delayed-quotes'
encodingStyle='http://schemas.xmlsoap.org/soap/encoding/'/>
</input>
<output>
<soap:body use='encoded' namespace='urn:xmethods-delayed-quotes'
encodingStyle='http://schemas.xmlsoap.org/soap/encoding/'/>
</output>
</operation>
</binding>
<service name='StockQuoteService'>
<port name='StockQuotePort' binding='StockQuoteBinding'>
<soap:address location='http://localhost/workspace/soap/stockquote1.php'/>
</port>
</service>
</definitions>
<input message='tns:getQuoteRequest'/>
<output message='tns:getQuoteResponse'/>
И вот код клиента (client.php):
PHP:
<?php
$client = new SoapClient("http://localhost/workspace/soap/stockquote1.wsdl");
try {
echo "<pre>\n";
print($client->getQuote("ibm"));
echo "\n";
print($client->getQuote("microsoft"));
echo "\n</pre>\n";
} catch (SoapFault $exception) {
echo $exception;
}
?>
В чем ошибка не врублюсь. Soap точно подключен и работает.SoapFault exception: [HTTP] Could not connect to host in /home/kotofeich/www/workspace/soap/client.php:5
Stack trace:
#0 [internal function]: SoapClient->__doRequest('__call('getQuote', Array)
#2 /home/kotofeich/www/workspace/soap/client.php(5): SoapClient->getQuote('ibm')
#3 {main}
Помогите пожалуйста.
P.S. Или покажите код примитивного рабочего сервера на soap.