tags:

views:

26

answers:

1

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/"&gt;&lt;SOAP-ENV:Body&gt;&lt;type&gt;Array&lt;/type&gt;&lt;xml/&gt;&lt;/SOAP-ENV:Body&gt;&lt;/SOAP-ENV:Envelope&gt;

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

+1  A: 

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);
Artefacto
The call is working! Now I see the xml string itself and not the Array text! But I got a SoapFault exception: [Client] looks like we got no XML document in....I made the xml paramater in this way:$string = <<<XML<?xml version="1.0" encoding="UTF-8"?><xml><referens><original_id>DH-2</original_id><name>Valaki</name><email>[email protected]</email><phone>06-30/375-3177</phone></referens></xml>XML;$xml = simplexml_load_string($string);
Tamas Gal
And I forgot: THANK YOU!
Tamas Gal
@Tamas Pass it the string directly, don't wrap it in a SimpleXMLElement object. I've checked the WSDL and it expects a string.
Artefacto
@Artefacto: I passed the string itself, but I got the same exception :( You can see the test page here: http://import.ingatlan.net/sky
Tamas Gal
Another interesting thing is that I try to use the __soapCall for another public function but it throws an error. It seems only working on the sendXml function.
Tamas Gal
@Tomas Well, that's a service-specific error. Your request is provoking some kind of error in the server (which, oddly, seems to be running xdebug).
Artefacto
@Artefacto - I found the problem finally! :) The SoapServer pointed a different WSDL file than the SoapClient. (I got a developer and a live copy....)But I accepst your answer because I find the solution based on that!
Tamas Gal