A
A
AlexEternal2015-04-12 15:44:14
PHP
AlexEternal, 2015-04-12 15:44:14

How to get the whole table in Soap client?

In general, my problem is that I do not understand how to process a request on the server that would return the entire table to the client, and the user does not know the number of records, not the number of columns, not their name. I tried to describe everything in the getAll function, but it didn't work out. I thought about giving the entire request to the variable and giving it to the client, but I get one error all the time: >Function ("getAll") is not a valid method for this service
It seems to be as described in the WSDL, I'm silent for the server, most likely there is some jamb. Please tell me how to send the entire table from mysql to the client without knowing anything about it, except for its name.
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 is my server
<?  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>

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexey Shein, 2015-04-12
@conf

Well, firstly, the getAll() function returns only 1 record from the database, and judging by the description, it should return an array of such records. Secondly, you need to describe it in the WSDL - i.e. that will return an array of entries, i.e. determine the type of such a record (describe its fields) and indicate that an array of these types is returned. Here is the first article that came across on Habré on which there is an example: habrahabr.ru/post/187390
Good luck!
PS You can also try some WSDL generator, for example, this one https://code.google.com/p/php-wsdl-creator/

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question