concurrent access to webservice object

8 views
Skip to first unread message

Chris Blackwell

unread,
Jul 20, 2009, 12:31:40 PM7/20/09
to cfc...@googlegroups.com
I'm using a webservice that requires that i first call a Login method, extract the returned cookie and pass that in subsequent requests. The object that brokers calls to this service is persisted in the application scope (via coldspring) so as not to require a call to Login for every request to the web service.  However, what i'm after is the SOAP xml returned in the response, not the java objects returned by cfinvoke, and to get at that i need to call a method on the cf webservice object after cfinvoke has called the method.  My assumption is that i'm going to need to single-thread access to the webservice object within the call method, otherwise i may get the xml from a request made in a different thread, but this is going to cause a severe bottleneck at a very busy point.

The code snippet below should give you an idea of what i'm upto.

I wondered if anyone might have any thoughts on whether this is the best way to handle this scenario?

Cheers, Chris

<cffunction name="init" access="public" output="false" returntype="any">
<cfargument name="username" type="string" required="true" />
<cfargument name="password" type="string" required="true" />
<cfset var my = structnew() />
<cfset variables.ws = createobject("webservice", variables.wsdlurl) />
<cfset variables.ws.setMaintainSession(true) />

<cfset my.ret = ws.Login(username, password) >
<cfset variables.cookie = variables.ws._getCall().getMessageContext().getProperty("Cookie") />
<cfset variables.cookie = listToarray(arrayToList(variables.cookie)) />
<cfset variables.ws._setProperty("Cookie", variables.cookie) />

<cfreturn this />
</cffunction>

<cffunction name="call" access="private" output="false" returntype="any">
<cfargument name="method" />
<cfargument name="args" />
<cfset var my = structnew() />

<cflock name="#variables.id#-call_lock"> 
<cfinvoke webservice="#variables.ws#" method="#method#" returnvariable="my.ret">
<cfloop collection="#args#" item="my.i">
<cfinvokeargument name="#my.i#" value="#args[my.i]#" />
</cfloop>
</cfinvoke>

<cfset my.ret = variables.ws._getCall().getMessageContext().getResponseMessage().getSOAPPartAsString() />

</cflock>

<cfreturn parseXml(my.ret) />
</cffunction>

Chris Blackwell

unread,
Jul 21, 2009, 4:51:15 AM7/21/09
to CFCDev
Tried to post this via email but didn't show up, so posting via web.
Apologies if it appears twice
Reply all
Reply to author
Forward
0 new messages