How to get session cookies from WSDL

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
victorsk
Forum Commoner
Posts: 43
Joined: Thu Apr 19, 2007 6:55 pm

How to get session cookies from WSDL

Post 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.
User avatar
pickle
Briney Mod
Posts: 6445
Joined: Mon Jan 19, 2004 6:11 pm
Location: 53.01N x 112.48W
Contact:

Post 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]
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
victorsk
Forum Commoner
Posts: 43
Joined: Thu Apr 19, 2007 6:55 pm

Post 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.
User avatar
pickle
Briney Mod
Posts: 6445
Joined: Mon Jan 19, 2004 6:11 pm
Location: 53.01N x 112.48W
Contact:

Post 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()
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
victorsk
Forum Commoner
Posts: 43
Joined: Thu Apr 19, 2007 6:55 pm

Post 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.
Post Reply