Page 1 of 1

How to get session cookies from WSDL

Posted: Thu Apr 19, 2007 7:02 pm
by victorsk
Hello,

I'm really quite new to PHP but need to figure out a way how to use remote WSDL API. For this I was told that I need to get a session cookie from WSDL containing session Id so I can make subsequent SOAP calls. I have no idea how to get this session cookie. I was able to successfully use Ping() function which means SOAP connection works, but that's as far as I went. This is my PHP code:

My wsdl.php file:

Code: Select all

<?
     require_once('SOAP/Client.php');
        $wsdl="http://yul.globaltsg.com//TSGWebServices/WebService.asmx?WSDL";


        $conn = new SOAP_WSDL($wsdl);
        $client = $conn->getProxy();
        $params = Array(
                        'agencyId'=>'123',
                        'userName'=>'sab',
                        'userPassword'=>'XXXX'
                );

        $prof_params = Array(
                        'username'=>'joe',
                        'password'=>'YYY'
                );
        $client->Login($params);
        $obj = $client->RetrieveAgentList();
        foreach($obj as $key => $value)
        {
                print "$key => $value\n";
        }
        //echo $client->RetrieveAgentList();    
?>
Here, I have to first Login() to use the rest of API, but this doesn't seem to work. This is the message I get from print "$key => $value\n" when I access my wsdl.php file in the browser:

"error_message_prefix => mode => 1 level => 1024 code => soap:Server message => Unhandled Exception userinfo => backtrace => Array callback =>"

Please help, I think I need to get a session cookie to make this work, but have no idea how to do this.

Thank you very much in advance,
Victor.

Posted: Fri Apr 20, 2007 11:05 am
by pickle
Usually, the login method will return a value that is supposed to be sent along with any subsequent SOAP requests. I'd examine the return value from $client->Login()

I've also edited your post to not have your passwords displayed, and I changed your [syntax=php][/syntax] blocks to [syntax="php"][/syntax]

Posted: Fri Apr 20, 2007 2:13 pm
by victorsk
Hi,

Thank you so much for replying. I tried to view the response using "echo" but because I'm new to PHP I'm not sure if this was the way to view the output from the response

this is the code snippet of my attempt:

Code: Select all

        
        $test = $client->Login($params);
        echo $test;
The result on the page was: "Object id #9"

Please, let me know what to do about this message, I have no idea what this means with PHP.

Thank you so much,
Victor.

Posted: Fri Apr 20, 2007 2:52 pm
by pickle
What that means is that $client->Login($params) returned an object. It has an internal id of 9 and you don't really need to know that.

Try:

Code: Select all

echo '<pre>';
print_r($test);
echo '</pre>'
That should output all the values stored in the object. You can also try var_dump() instead of print_r()

Posted: Fri Apr 20, 2007 3:56 pm
by victorsk
Thank you again for replying. I've got more information but there was no sessionId there. I guess it's up to me now to find out why :cry:

Thank you,
Victor.