SoapServer::setPersistence() [<a href='function.SoapServer-
setPersistence'>function.SoapServer-setPersistence</a>]: Tried to set
persistence when you are using you SOAP SERVER in function mode, no
persistence needed
The script works without setPersistence but doesn't keep the session
alive between calls.
The basic order of events in the server script are as follows:
1. include config.php: database connection, session_start, constants,
session variable initialization, class definitions
1a. destroy the session, start a new session
2. $user=getCurrentUser(); # gets the session's user object
3. $server=new SoapServer;
4. data manipulation, error handling
5. set persistence of the server
6. set the server's object as user
7. $server->handle($data); # handle the data, send back XML reply
I appreciate any and all help in terms of what the error means or how
to fix it. Thanks!
<?
ob_start();
// class definitions, session starting, session variable
initialization, db connection
require_once "../../config.php";
session_destroy(); // get rid of the config's session
// Change the session to a SOAP session for this and all SOAP scripts.
// Make the session name unique to the IP.
$sessionId="SoapUserid".$_SERVER['REMOTE_ADDR'];//.$user->id();
$oldSessionId=session_id($sessionId);
session_start();
$user=getCurrentUser(); // gets a default User object
// get XML data for SOAP
$data=$HTTP_RAW_POST_DATA;
//$data=sampleXml();
// make the server, modify it in the script
$server=new
SoapServer(null,array('soap_version'=>SOAP_1_2,'uri'=>TP."://".DOMAIN));
// log in if the call is for "setupUser"
if(preg_match('/setupUser/',$data)){
$setupUserParam=array();
// need parameters from xml
$xml=new XMLReader();
$xml->xml($data);
$xml->moveToAttribute("namesp2");
while($xml->read()){
// start paying attention if we get the opening tag
if($xml->localName=="setupUser"){
// get each parameter
while($xml->read()){
if($xml->hasValue){
array_push($setupUserParam,$xml->value);
}
// break out if it's the closing tag
if($xml->localName=="setupUser"){
break;
}
}
}
}
$user=new User($setupUserParam[0],$setupUserParam[1]);
$_SESSION['user']=$user;
}
#$server->fault("user info","$oldSessionId,$sessionId,".print_r($user-
>getInfo(),true));
// error handling
if($user->error){
$server->fault("User error",$user->error,"User");
}
$server->setPersistence(SOAP_PERSISTENCE_SESSION);
$server->setObject($user);
ob_end_clean();
$server->handle($data);
session_write_close();
function sampleXml(){
$tmpXml='<?xml version="1.0" encoding="UTF-8"?><SOAP-ENV:Envelope
xmlns:xsi="http://www.w3.org/1999/XMLSchema-instance" xmlns:SOAP-
ENC="http://schemas.xmlsoap.org/soap/encoding/" xmlns:SOAP-ENV="http://
schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/1999/
XMLSchema" SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/
encoding/"><SOAP-ENV:Body><namesp2:setupUser xmlns:namesp2="http://
mgip2.biology.gatech.edu"><c-gensym4 xsi:type="xsd:string">demo</c-
gensym4><c-gensym6 xsi:type="xsd:string">demo</c-gensym6></
namesp2:setupUser></SOAP-ENV:Body></SOAP-ENV:Envelope>';
return $tmpXml;
}
?>
And also, what is function mode?
<?
class Test{
private $var;
function __construct(){
$this->var=0;
}
function addOne(){
$this->var++;
return $this->getVar();
}
function subtractOne(){
$this->var--;
return $this->getVar();
}
function getVar(){
return $this->var;
}
}
$data=$HTTP_RAW_POST_DATA;
$one=new Test();
session_start();
$server=new
SoapServer(null,array('soap_version'=>SOAP_1_2,'uri'=>"http://
mgip2.biology.gatech.edu"));
$server->setPersistence(SOAP_PERSISTENCE_SESSION);
#$server->setObject($one);
$server->setClass('Test');
$server->handle($data);
?>
You must call setPersistance after setObject/setClass.
Regards
Jonathan
Thank you, but modified script below still has the same error. What
could the problem be? What is function mode?
<?
class Test{
private $var;
function __construct(){
$this->var=0;
}
function addOne(){
$this->var++;
return $this->getVar();
}
function subtractOne(){
$this->var--;
return $this->getVar();
}
function getVar(){
return $this->var;
}
}
$data=$HTTP_RAW_POST_DATA;
$one=new Test();
session_start();
$server=new
SoapServer(null,array('soap_version'=>SOAP_1_2,'uri'=>"http://
mgip2.biology.gatech.edu"));
$server->setObject($one);
#$server->setClass('Test');
$server->setPersistence(SOAP_PERSISTENCE_SESSION);
$server->handle($data);
?>
> $server->setObject($one);
> #$server->setClass('Test');
I see that you switched back to "setObject" instead of "setClass". I got
you example working (at least I got it running without error messages)
with "setClass".
I think this is a bug with the combination of setObject and setPersistence.
If you can rewrite your code to use setClass, I guess that's the best
solution at the moment.
I've created a bug report for the issue:
http://bugs.php.net/bug.php?id=51475
> What is function mode?
That's when you don't use a class/object to handle the request.
Regards
Jonathan
Well, the problem occurs with either setObject or setClass.
> I think this is a bug with the combination of setObject and setPersistence.
> If you can rewrite your code to use setClass, I guess that's the best
> solution at the moment.
Thanks for submitting the bug report and letting me know what function
mode is. So, setObject/setClass has never been used with persistence
or sessioning? I will try to think of a workaround but I don't think
that setClass worked for me.
Does anyone have a working setClass or setObject example that uses
persistence or sessioning?
> Does anyone have a working setClass or setObject example that uses
> persistence or sessioning?
Yes, I got your example running with "setClass".
I used this server:
http://www.jsp-hotel.dk/test/soappersistence-setClass.php
(source: http://www.jsp-hotel.dk/test/soappersistence-setClass.txt )
with this client:
http://www.jsp-hotel.dk/test/soapclient.php
(source: http://www.jsp-hotel.dk/test/soapclient.txt )
I was testing with PHP 5.2.8.
Regards
Jonathan
--
Er din email vigtig? Er du træt af, at din hjemmeside er nede?
Stabilt webhotel på redundant setup med daglig backup.
POP3, IMAP, PHP, JSP, Java, Perl, Python, Telnet, SSH, Cron-jobs m.v.
http://www.jsp-hotel.dk/
Jonathan, you have been very helpful. Thank you! This example
works. However, I cannot get it to work in a client Perl Soap::Lite
script (which is my ultimate goal). I will CC comp.lang.perl.misc to
continue this conversation. The first part of this conversation can
be found at comp.lang.php (http://groups.google.com/group/
comp.lang.php/browse_thread/thread/7657d5bf882f287b/
4f89ac2542e7ba7c#4f89ac2542e7ba7c)
Basically, I want to use a PHP Soap Server with a Perl client script.
Above is Jonathan's example PHP server and client that work
together.
Below is the Perl script that works, but it does not keep the session
alive I think. In other words, it is not maintaining a class variable
between soap calls.
use strict;
use warnings;
use Data::Dumper;
use SOAP::Lite;# on_debug => sub{print@_};
my($response,$value);
my $soap = SOAP::Lite
-> uri('http://mgip2.biology.gatech.edu')
-> proxy('http://mgip2.biology.gatech.edu/api/apiServer4.php')
;
$response=$soap->subtractOne;
$response=$soap->subtractOne;
$response=$soap->subtractOne;
print valueToString($response);
# put the response's value into a string
sub valueToString{
my($response)=@_;
my $value=$response->faultstring||$response->result||"";
if(ref($value) eq "HASH"){
# get all keys and values from hash
my $str="";
while(my($k,$v)=each(%$value)){
$str.="$k=>$v, ";
}
$value=$str;
}
elsif(ref($value) eq "ARRAY"){
# join the array
$value=join(" ",@$value);
}
return $value;
}