glebvvvsss
@glebvvvsss

Почему возникает ошибка в soap запросе 'not valid method'?

Добрый день. Вопрос может показаться детским для людей, которые плотно работают с веб сервисами, но я нахожусь в процессе обучения и решил разобраться с основными принципами работы с SOAP через php.

вот полное содержание ошибки: Fatal error: Uncaught SoapFault exception: [Client] Function ("getStock") is not a valid method for this service in E:\servNew\OSPanel\domains\test-soap\index.php on line 8

вот мой сервер:
<?php 

function getStock($id) {
	$stock = [
		'1' => 100,
		'2' => 200,
		'3' => 300,
		'4' => 400,
	];

	$quantity = $stock[$id];
	return $quantity;
}

ini_set('soap.wsdl_cache_enabled', '0');
$server = new SoapServer( 'test.wsdl' );
$server->addFunction('getStock');
$server->handle();

?>


вот клиент:
<?php 

$client = new 
    SoapClient( 
        "test.wsdl" 
    ); 

$client->getStock('1'); 

?>


wsdl файл:
<?xml version ='1.0' encoding ='UTF-8' ?> 
<definitions name='Stock' 
 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='getStockRequest'>
  <part name='id' type='xsd:string'/>
</message>

<message name='getStockResponse'>
  <part name='Result' type='xsd:integer'/>
</message>

<portType name='StockPortType'>
  <operation name='getStock'>
    <input message='tns:getStockRequest'/>
    <output message='tns:getStockResponse'/>
  <operation>
<portType>

<binding name='StockBinding' type='tns:StockPortType'>
  <soap:binding style='rpc' transport='http://schemas.xmlsoap.org/soap/http'/>
  <operation name='getStock' />
<binding>

<service name='StockService'>
  <port name='StockPort' binding='StockBinding'>
    <soap:address location='test.wsdl'/>
  <port>
</service>

</definitions>
  • Вопрос задан
  • 610 просмотров
Пригласить эксперта
Ответы на вопрос 1
SilenceOfWinter
@SilenceOfWinter Куратор тега PHP
та еще зажигалка...
Исключение SoapFault будет брошено, если wsdl URI не может быть загружена.

Очевидно клиент ждет абсолютный/полный url.
Ответ написан
Комментировать
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы