Problem statement
Making multiple calls to SOAP is an expensive step for memory and database, therefore, using a session scope for web services becomes critical.
Workaround
Add a session cookie to an HTTP request header when invoking a SOAP service in ColdFusion and establish the session scope if the scope exists for the cookie. Using this procedure, you can add HTTP request header to the SOAP invocation.
As a workaround, you can pass JSessionId cookies and allow web service sessions. You can then reduce the number of invokes on every web service call.
SOAPservice.cfc
component style="document"
{
remote any function echoString(required string argString)
{
headers = GetHttpRequestData();
return SerializeJSON(headers.headers);
}
}
For Axis2, use the service SOAPservice above to create the object.
invokeaxis2.cfm
<cfscript>
wsobj = createObject("webservice", "http://localhost:8500/path/to/soapservice.cfc?wsdl",{wsversion="2"});
list = createObject("java","java.util.ArrayList").init();
testHeader = createObject("java","org.apache.axis2.context.NamedValue").init("testheader","testHeadervalue");
list.add(testHeader);
wsobj._getServiceClient().getOptions().setManageSession(true);
wsobj._getServiceClient().getOptions().setProperty("HTTP_HEADERS",list);
wsobj._getServiceClient().getOptions().setProperty("Cookie","JSESSIONID=#COOKIE["JSESSIONID"]#");
result = wsobj.echoString("Hello World");
writeDump(result);
</cfscript>
For Axis1, use the same service as above.
invokeaxis1.cfc
<cfscript>
wsobj = createObject("webservice", "http://localhost:8500/path/to/soapservice.cfc?wsdl",{wsversion="1"});
headers = createObject("java","java.util.Hashtable").init();
headers.put("testheader","testHeadervalue");
wsobj.setMaintainSession(true);
wsobj._setProperty("HTTP-Request-Headers", headers);
wsobj._setProperty("Cookie","JSESSIONID=#COOKIE["JSESSIONID"]#");
result = wsobj.echoString("Hello World");
writeDump(result);
</cfscript>