Tamas Gal
Tamas Gal

Reputation: 33

Strange problems with PHP SOAP (private variable not persist + variables passed from client not working)

I have a very strange problems in a PHP Soap implementation.

1) I have a private variable in the Server class which contains the DB name for further reference. The private variable name is "fromdb". I have a public function on the soap server where I can set this variable. $client->setFromdb. When I call it form my client works perfectly and the fromdb private variable can be set. But a second soap client call this private variable loses its value... Here is my soap server setup:

ini_set('soap.wsdl_cache_enabled', 0);
ini_set('session.auto_start', 0); 
ini_set('always_populate_raw_post_data', 1);

global $config_dir;

session_start();

/*if(!$HTTP_RAW_POST_DATA){
    $HTTP_RAW_POST_DATA = file_get_contents('php://input');
  }*/

$server = new SoapServer("{$config_dir['template']}import.wsdl");  
$server->setClass('import');
$server->setPersistence(SOAP_PERSISTENCE_SESSION);
$server->handle();

2) Problem is that I passed this to the server:

$client = new SoapClient('http://import.ingatlan.net/wsdl', array('trace' => 1));
$xml='<?xml version="1.0" encoding="UTF-8"?>';
$xml.='<xml>';
$xml.='<referens>';
$xml.='<original_id><![CDATA[DH-2]]></original_id>';
$xml.='<name>Valaki</name>';
$xml.='<email><![CDATA[[email protected]]]></email>';
$xml.='<phone><![CDATA[06-30/111-2222]]></phone>';
$xml.='</referens>';
$xml.='</xml>';


$tarray = array("type" => 1, "xml" => $xml);
try {
    $s = $client->sendXml( $tarray );
    print "$s<br>";
}
catch(SOAPFault $exception) { 

    print "<br>--- SOAP exception :<br>{$exception}<br>---<br>";

    print "<br>LAST REQUEST :<br>";
    var_dump($client->__getLastRequest());
    print "<br>---<br>";
    print "<br>LAST RESPONSE :<br>".$client->__getLastResponse();

}

So passed an Array of informations to the server. Then I got this exception: LAST REQUEST :

<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"><SOAP-ENV:Body><type>Array</type><xml/></SOAP-ENV:Body></SOAP-ENV:Envelope>

Can you see the Array word between the type tag? Seems that the client only passed a reference or something like this. So I totally missed :(

Upvotes: 1

Views: 1870

Answers (1)

Artefacto
Artefacto

Reputation: 97835

It seems the SOAP extension is expecting a string, but you're giving it an array. It then tries to convert the array into a string, resulting in "Array". I don't have time to check right now what the extension does you write $client->sendXml( $tarray );, but try to use instead:

$client->__soapCall("sendXml", $tarray);

Upvotes: 1

Related Questions