Это песец просто. .. Есть например такой кусок кода, который нашёл в нескольких местах.
$client = new SoapClient("http://www.freewebs.com/jimmy_cheng/CurrencyExchangeService.wsdl");
$result = $client->getRate("us", "russia");
echo 'Текущий курс доллара: '. $result. ' рублей';
Не работает. На экране ничего нет. В чём тут проблема?
Спустя 2 часа, 21 минута, 52 секунды (16.07.2011 - 22:20) Guest написал(а):
Спустя 7 часов, 53 минуты, 28 секунд (17.07.2011 - 06:14) finder128 написал(а):
Цитата (Guest @ 16.07.2011 - 19:20) |
http://phpclub.ru/detail/article/soap |
Видел я этот пример. Он довольно громоздкий, полностью я его не проверял, но один из кусков точно не работает. Например:
ini_set("soap.wsdl_cache_enabled", "0"); // отключаем кэширование WSDL
$client = new SoapClient("stockquote.wsdl");
var_dump($client->__getFunctions());
print($client->getQuote("ibm"));
Ini_set и var_dump я добавил сам, они особой роли не играют.
Var_dump результат выдаёт, print нет. Пример нерабочий.
Так и не понятно, как извлекать инфу из vsdl.
Что, спецов по soap на форуме нет?
Спустя 5 часов, 39 минут, 14 секунд (17.07.2011 - 11:53) Guest написал(а):
Файл soap.php
<?php
$quotes = array(
"ibm" => "<script>alert('test.php прекрасно отвечает');</script>"
);
class QuoteService {
private $quotes = array("ibm" => "<script>alert('test');</script>");
function getQuote($symbol) {
if (isset($this->quotes[$symbol])) {
return $this->quotes[$symbol];
}
//else {
// throw new SoapFault("Server","Unknown Symbol '$symbol'.");
//}
}
}
$server = new SoapServer("index.wsdl");
$server->setClass("QuoteService");
$server->handle();
?>
Файл index.wsdl
<?xml version ='1.0' encoding ='UTF-8' ?>
<definitions name='StockQuote'
targetNamespace='http://example.org/StockQuote'
xmlns:tns=' http://example.org/StockQuote '
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:string'/>
</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='QuoteService'>
<soap:operation soapAction='urn:xmethods-delayed-quotes#QuoteService'/>
<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://site.ru/soap.php'/>
</port>
</service>
</definitions>
Файл test.php
<?php
$client = new SoapClient("index.wsdl");
try {
echo "<pre>\n";
print($client->getQuote("ibm"));
echo "\n";
print($client->getQuote("microsoft"));
echo "\n</pre>\n";
} catch (SoapFault $exception) {
echo $exception;
}
?>
В файле index.wsdl измените адрес сайта на свой и запускайте test.php
Свернутый текст
<?php
$quotes = array(
"ibm" => "<script>alert('test.php прекрасно отвечает');</script>"
);
class QuoteService {
private $quotes = array("ibm" => "<script>alert('test');</script>");
function getQuote($symbol) {
if (isset($this->quotes[$symbol])) {
return $this->quotes[$symbol];
}
//else {
// throw new SoapFault("Server","Unknown Symbol '$symbol'.");
//}
}
}
$server = new SoapServer("index.wsdl");
$server->setClass("QuoteService");
$server->handle();
?>
Файл index.wsdl
Свернутый текст
<?xml version ='1.0' encoding ='UTF-8' ?>
<definitions name='StockQuote'
targetNamespace='http://example.org/StockQuote'
xmlns:tns=' http://example.org/StockQuote '
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:string'/>
</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='QuoteService'>
<soap:operation soapAction='urn:xmethods-delayed-quotes#QuoteService'/>
<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://site.ru/soap.php'/>
</port>
</service>
</definitions>
Файл test.php
Свернутый текст
<?php
$client = new SoapClient("index.wsdl");
try {
echo "<pre>\n";
print($client->getQuote("ibm"));
echo "\n";
print($client->getQuote("microsoft"));
echo "\n</pre>\n";
} catch (SoapFault $exception) {
echo $exception;
}
?>
В файле index.wsdl измените адрес сайта на свой и запускайте test.php
Спустя 4 месяца, 12 дней, 2 часа, 52 минуты, 36 секунд (29.11.2011 - 14:45) Guest написал(а):
пример в первом сообщении меня не работает. выдаёт SOAP-ERROR: Parsing WSDL: Couldn't load from 'http://www.freewebs1.com/jimmy_cheng/CurrencyExchangeService.wsdl' : failed to load external entity "http://www.freewebs1.com/jimmy_cheng/CurrencyExchangeService.wsdl" .
последний пример не работает воообще - ошибка 500.
в чём дело?
последний пример не работает воообще - ошибка 500.
в чём дело?
Спустя 14 часов, 53 минуты, 51 секунда (30.11.2011 - 05:39) Guest написал(а):
Последний пример отлично работает, я протестировал прежде чем написать ответ. Потом, первый пример выдает у вас ошибку синтаксиса wsdl, значит поддержка soap есть. Исправьте index.wsdl под себя (свой сайт укажите) и все заработает. Быть может .htaccess мешает, посмотрите логи. Разбирайтесь, не делать же вам пошаговую инструкцию. Понимание того, что это просто, придет сразу как запустите тестовый скрипт. Все дальнейшие проблемы поможет решить print_r или var_dump.
Спустя 4 часа, 56 минут, 53 секунды (30.11.2011 - 10:36) Guest написал(а):
добавив try ... catch в test.php
получил следующее сообщение SOAP-ERROR: Parsing WSDL: Missing / with name 'QuoteService' in C:\htdocs\test.php:3 Stack trace: #0 C:\htdocs\test.php(3): SoapClient->SoapClient('http://172.24.0...') #1 {main}
в index.wsdl сайт заменил, .htaccess точно не мешает.
Буду ковырять дальше.
получил следующее сообщение SOAP-ERROR: Parsing WSDL: Missing / with name 'QuoteService' in C:\htdocs\test.php:3 Stack trace: #0 C:\htdocs\test.php(3): SoapClient->SoapClient('http://172.24.0...') #1 {main}
в index.wsdl сайт заменил, .htaccess точно не мешает.
Буду ковырять дальше.
Спустя 54 минуты, 36 секунд (30.11.2011 - 11:31) Guest написал(а):
запустил пример отсюда http://phpclub.ru/detail/article/soap
всё заработало. теперь копаю в сторону веб-сервисов 1с
всё заработало. теперь копаю в сторону веб-сервисов 1с