Forum Moderators: coopster

Message Too Old, No Replies

NuSOAP and Persistant Data: Any ideas?

How to get NuSOAP to remember values between function calls...

         

hollow

12:14 pm on Jun 17, 2004 (gmt 0)

10+ Year Member



Hopefully some of you folks will have some ideas on this one. I've been experimenting with NuSoap for a few hours and have gotten a basic server/client helloworldy type thing up and running, but where i'm running into difficulties is making data persist between function calls. Each function call is presumably a seperate http request, so it occurred to me to use $_SESSION's but I think I misunderstood how this kind of thing works.

Anyway... here's the code, which will probably give more of an idea of what i'm after:

SERVER:

// $namespace defined earlier in script
$vars = array();
$server = new soap_server();
$server->debug_flag=false;
$server->configureWSDL('Testing Soap', $namespace);
$server->wsdl->schemaTargetNamespace = $namespace;

$server->register('setValue',
array('inputVar'=>'xsd:string','inputString'=>'xsd:string'),
array('return'=>'xsd:string'),
$namespace);

function setValue($var,$string)
{
global $vars;
$vars[$var]=$string;
return $vars[$var];
}

$server->register('getValue',
array('inputString'=>'xsd:string'),
array('return'=>'xsd:string'),
$namespace);

function getValue($var)
{
global $vars;
return $vars[$var];
}
$server->service($HTTP_RAW_POST_DATA);

CLIENT:

// $wsdl and $namespace defined earlier in script
$client=new soapclient($wsdl, 'wsdl');
$client->useHTTPPersistentConnection();

// NOTE: recurseArray() is a function of my own which just dumps the contents of the input into a list.

$result = $client->call('setValue', array("name","paul"),$namespace);
recurseArray($result);
// returning 'paul', which is what I would expect.

$result = $client->call('getValue', array("name"),$namespace);
recurseArray($result);
// nothing returning, I want it to return 'paul'

bsterz

12:58 pm on Jun 17, 2004 (gmt 0)

10+ Year Member



Greetings hollow!

Sorry - I'm not real familiar with nusoap, but I think if I were tackling this thing, I would maintain state on the client (website calling the service) side and pass the state to the web service with each call. Take what you get back from the service and "update" your state. You could pass the entire $_SESSION array to your service and it could grab what it needs.

Hope this helps,

Bill

hollow

1:06 pm on Jun 17, 2004 (gmt 0)

10+ Year Member



Cheers, bsterz, yeah, my reading seems to be suggesting this as the way, but i'm trying to figure out how best to go about it, something like this would work but seems a little clumsy. Part of the reason I wanted to maintain state on the server was because I don't want to trust the client to say whether or not it's authenticated...

Not sure if this will make sense:

$session = $client->call('getSessionId',array("username","password"),$namespace);

//To get an id from the server and then passing this as the first parameter with every subsequent call...

$result = $client->call('setValue', array($session,"name","paul"),$namespace);
recurseArray($result);

$result = $client->call('getValue', array($session,"name"),$namespace);
recurseArray($result);

I've seen mention that you could pass the id in the SOAP header, but I really don't want to get into the actual XML that's being generated here unless I absolutely have to...