WebSphere Message Service Clients: Web Services Client for C++, Version 1.1 Operating Systems: Linux, Windows

Cookie support

This section describes the cookie support that Web Services Client for C++ provides, including getting cookies from services and adding cookies to other services, and removing cookies from stub instances.

Cookie attributes

The following table summarizes how Web Services Client for C++ handles cookie attributes.

Table 1. Behavior of Web Services Client for C++ with regard to cookie attributes
Attribute Behavior
expires This attribute is ignored. If a server sends a signal to the client asking it to expire a cookie, the client does not do so. Once set by a server, the client continues to send cookies on each request using that stub. If a new stub instance is created and used, then the cookies from the original stub instance are not sent on requests from the new stub instance.
path This attribute is ignored. Cookies are sent on all requests and not just on requests to a URI applicable to the path.
domain This attribute is ignored. Cookies have affinity to a stub and are domain neutral.
secure This attribute is ignored. If secure is set on a cookie, this has no effect and the cookie is sent on all future requests regardless of whether the channel is secure or not.

Use of cookies across multiple stub instances

If cookies are required in a different instance of a stub such as when a login is done on one service and the login session cookies are required on other services, you can use the APIs in the following example. This example uses two instances of the calculator service and a login service. The first instance uses the login service and receives some cookies back representing the session cookies. These cookies are required for interacting with the calculator service in order to authenticate to the server that hosts the calculator service.

Call the webservice
LoginService loginService("http://loginserver/loginservice");

// must tell the service to save cookies
loginService.setMaintainSession(true);

// login so that we can get the session cookies back
loginService.login("myusername", "mypassword");

// Store the cookies so they can be given to the Calculator web service as 
// authentication.
	int currentCookieKey=0;
	string cookieKeys[2];
	const char* key = loginService.getFirstTransportPropertyKey();
	string keyString(key);
	if(key)
        {
		// Only get the "Set-Cookie" transport properties - as these are what the server 
   // sends to the client to set cookies.
            if(keyString.compare("Set-Cookie")==0)
            {
             string valueString(loginService.getCurrentTransportPropertyValue());
             cookieKeys[currentCookieKey++] = valueString;
            }
        }
        // then the rest of the cookies
        while(key = loginService.getNextTransportPropertyKey())
        {
            string nextKeyString(key);
		// Only get the "Set-Cookie" transport properties - as these are what the server 
  // sends to the client to set cookies.
            if(nextKeyString.compare("Set-Cookie")==0)
            {
             string valueString(loginService.getCurrentTransportPropertyValue());
            cookieKeys[currentCookieKey++] = valueString;
            }
        }
// Now we've logged in and stored the cookies we can create the calculator service, 
// set the cookies on that stub instance and use the calculator.
        Calculator calculator("http://calculatorserver/calculatorservice);
        calculator.setMaintainSession(true);
        // OK, Now add the previously saved session cookies on to this new service 
        // as this service does not pick up the cookies from the other stub.
        currentCookieKey=0;
        while(currentCookieKey< 3)
        {
            calculator.setTransportProperty("Cookie", 
            cookieKeys[currentCookieKey++].c_str());
        }

	// Now, when we use the service it will send the session cookies to the server 
 // in the http message header
 // which allows the server to authenticate this instance of the service.
	int result = calculator.add(1,2);

	// If we continue to use this instance of the calculator stub then the cookies
 // will be continue to be sent.
	result = calculator.add(1,2);

	// If we use a new instance of the calculator then it will fail because we have
 // not set the cookies
	Calculator newCalculatorInstance("http://calculatorserver/calculatorservice);
	// This will fail with an exception because we have not set the authentication
 // cookies
	result = newCalculatorInstance.add(1,2);

Manipulation of cookies

It is sometimes necessary to remove cookies from stub instances.


Reference topic

Terms of Use | Rate this page

Last updated: 25 Jan 2006

© Copyright IBM Corporation 2005, 2006. All Rights Reserved.