1
votes

I can not get my php to set a value in the SOAP Header.

my code is

$requestParams = 'Parameters I am passing into the WS'

$client = new SoapClient('https://webservice.wsdl',array(
                'login' => "user",
                'password' => "password",
                'trace' => 1,
                'sessionID' => "93b23bb6e611db8548f2ee9485bc7d17"));

$client->submitRequest($requestParams);

process returned code and it does return what I expect

then

$client->release();

which should release this sessionID

The Web service I am calling uses a sessionID variable and if one is not passed it will create one for you but you can only have 5 unique sessions created before it locks you out for 5 min.

If you open a session you can reuse it as long as you free a session off and don't have more than five open.

My problem is that everything works but the web service does not see my sessionID variable because every time I make a call it issues me a new sessionID. So it created 5 new sessionID's and I have no way of freeing them off when completed and I have to wait till they timeout on the server.

Web Service Call #1 string(414) "HTTP/1.1 200 OK Date: Fri, 01 Aug 2014 20:56:32 GMT Server: Apache Set-Cookie: PHPSESSID=ee6d8e3f9e6e1b9dac35e10f917a69c8; path=/ Expires: Thu, 19 Nov 1981 08:52:00 GMT Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0 Pragma: no-cache Set-Cookie: PHPSESSID=ee6d8e3f9e6e1b9dac35e10f917a69c8; path=/ Content-Length: 560 Connection: close Content-Type: text/xml; charset=utf-8 "

Web Service Call #2 string(414) "HTTP/1.1 200 OK Date: Fri, 01 Aug 2014 20:57:18 GMT Server: Apache Set-Cookie: PHPSESSID=46d99f3b92d095981119b7050686967c; path=/ Expires: Thu, 19 Nov 1981 08:52:00 GMT Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0 Pragma: no-cache Set-Cookie: PHPSESSID=46d99f3b92d095981119b7050686967c; path=/ Content-Length: 560 Connection: close Content-Type: text/xml; charset=utf-8 "

And So on Till I get A connection refused and I have to wait. If the session ID was passed in the SOAP HEADER from the code above the response would look like.

string(414) "HTTP/1.1 200 OK Date: Fri, 01 Aug 2014 20:58:18 GMT Server: Apache Set-Cookie: PHPSESSID=93b23bb6e611db8548f2ee9485bc7d17; path=/ Expires: Thu, 19 Nov 1981 08:52:00 GMT Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0 Pragma: no-cache Set-Cookie: PHPSESSID=93b23bb6e611db8548f2ee9485bc7d17; path=/ Content-Length: 560 Connection: close Content-Type: text/xml; charset=utf-8 "

1

1 Answers

2
votes

You need to use the _cookies and the __setCookie methods on the SoapClient class to get and set the Session ID for use during SOAP calls.

Your code would look like this:

$requestParams = 'Parameters I am passing into the WS'
$sessionId = "93b23bb6e611db8548f2ee9485bc7d17";

$client = new SoapClient('https://webservice.wsdl',array(
                'login' => "user",
                'password' => "password",
                'trace' => 1));
$client->__setCookie('PHPSESSID', $sessionId);

// ... your requests

If you are making the calls in separate stateless runs of the script, then you also would need to setup some method of persistence to make the Session ID persist between uses.