AlexEternal
@AlexEternal

Как получение всей таблицы в Soap клиенте?

В общем моя проблема состоит в том, что я не понимаю как обработать на сервере запрос, который бы вернул клиенту всю таблицу, причём пользователь не знает не количество записей, не количество стобцов, не их название. Я пытался описать всё в функции getAll, но так и не вышло. Думал отдать весь запрос переменной и её отдать клиенту, но получаю всё время одну ошибку: >Function ("getAll") is not a valid method for this service
Вроде бы как всё описал в WSDL, за сервер молчу скорее всего там какой косяк. Подскажите пожалуйста, как правильно отправить клиенту всю таблицу из mysql, не зная о ней ничего, кроме её названия.

Client.php
<?
header("Content-Type: text/html; charset=utf-8");
$client = new SoapClient("news.wsdl");
	try {
$result=$client->getByid("2");
		$result1=$client->getAll();
		echo "Ответ сервера: ", $result;
		echo "<br>";
		echo "Совсем другой ответ: ",$result1; 
		} 
	catch(SoapFault $e)
		{
	  echo 'Тут '.$e->faultcode.' вернул ошибку: '.$e->getMessage();
		}
?>


news.php - это сервер мой
<?  require_once("DB_Connect.php");
      function getByID ($id) 
		{
		$q=mysql_query("select * from followers where $id=id");
		$ret=mysql_fetch_array($q);
		if (isset($ret['slovo']))
			{
	   		$otvet=$ret['slovo'];
			return $otvet;
			}
			else{ return "Нет записи.Для такого индефикатора";}
		}
	    function getAll () 
		{
		  $qu=mysql_query("select * from followers");
          $red=mysql_fetch_array($qu);
          return $red;
		       	}
	ini_set("soap.wsdl_cache_enabled", "0");
	ini_set("soap.wsdl_cache_ttl", "0");
	$server = new SoapServer("news.wsdl");
	$server->addFunction(array("getByID","getAll"));
	//$server->addFunction("getAll");
	$server->handle();
?>


Db_connect.php
<?
$dbhost="localhost";
$dblogin="root";
$dbname ="test";

    $db=mysql_connect($dbhost,$dblogin,$dbpass);
    if (!$db)
        {
            echo "Unable to connect to DB: " . mysql_error();
            exit;
        }
    if (!mysql_select_db($dbname))
        {
            echo "Unable to select mydbname: " . mysql_error();
            exit;
        }
    mysql_query("set character set utf8");
?>


news.wsdl
<?xml version='1.0' encoding='UTF-8'?>
<definitions name="news" targetNamespace="http://soap.local/" xmlns:tns="http://soap.local/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" 
xmlns="http://schemas.xmlsoap.org/wsdl/">
       
	   <message name="getByIDRequest">
            <part name="id" type='xsd:integer'/>
        </message>
        <message name="getByIDResponse">
            <part name="result" type='xsd:string'/>
        </message>
		
		<message name="getAllReq">
			<part name="result" type='xsd:string'/>		
        </message>
        <message name="getAllRes">
            <part name="result" type='xsd:string'/>
        </message>

        <portType name="newsPortType">
            <operation name="getByID">
                <input message="tns:getByIDRequest"/>
                <output message="tns:getByIDResponse"/>
            </operation>
			
			<operation name="getAll">
                <input message="tns:getAllReq"/>
                <output message="tns:getAllRes"/>
            </operation>
        </portType>
		
        <binding name="newsBinding" type="tns:newsPortType">
            <soap:binding style="rpc" transport="http://schemas.xmlsoap.org/soap/http"/>
            
			<operation name="getByID">
			</operation>
			
			<operation name="getAll">
			</operation>
		</binding>
		
        <service name="newsService">
            <port name="newsPort" binding="newsBinding">
                <soap:address location="http://soap.local/news.php"/>
            </port>
        </service>
</definitions>
  • Вопрос задан
  • 443 просмотра
Пригласить эксперта
Ответы на вопрос 1
conf
@conf
Ruby developer
Ну, во-первых, функция getAll() у вас возвращает только 1 запись из базы, а должна судя по описанию - массив из таких записей. Во-вторых, нужно описать это в WSDL - т.е. что будет возвращаться массив из записей, т.е. определить тип такой записи (описать ее поля) и указать что возвращается массив этих типов. Вот первая попавшаяся статья на хабре на которой есть пример: habrahabr.ru/post/187390
Удачи!

P.S. Еще можно попробовать какой-нибудь WSDL-генератор, например, этот https://code.google.com/p/php-wsdl-creator/
Ответ написан
Ваш ответ на вопрос

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

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