Reputation: 4701
I have a simple cffunction that calls a webservice and returns a token. It's been working for quite sometime, but recently it's returning nothing.
<cffunction name="getICEToken" access="public" output="no" returntype="string" returnformat="plain" description="Sets token for access to ICE webservices">
<cfargument name="username" type="string" required="yes" />
<cfargument name="password" type="string" required="yes" />
<cfargument name="memberID" type="string" required="yes" />
<cfargument name="partnerID" type="string" required="no" default="#this.partnerID#">
<!--- initialize local var to hold method-specific vars --->
<cfset var local=structnew()>
<cftry>
<cfscript>
local.postTo='/membership/Member.asmx';
local.soapAction = 'someURL';
local.method = 'AuthenticateUserByMemberId2';
local.myAccessToken = '';
</cfscript>
<!--- generate soap request content to get our access token --->
<cfsavecontent variable="soapBody">
<cfoutput>
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<#local.method# xmlns="#local.soapAction#">
<WsUserName>#xmlformat(arguments.username)#</WsUserName>
<WsPassword>#xmlformat(arguments.password)#</WsPassword>
<PartnerId>#xmlformat(arguments.partnerID)#</PartnerId>
<MemberId>#xmlformat(arguments.memberID)#</MemberId>
</#local.method#>
</soap:Body>
</soap:Envelope>
</cfoutput>
</cfsavecontent>
<!--- send webservice request to ICE --->
<cfhttp url="https://#this.host##local.postTo#" method="post" result="local.httpResponse">
<cfhttpparam type="header" name="SOAPAction" value="#local.soapAction##local.method#" />
<cfhttpparam type="header" name="accept-encoding" value="deflate;q=0">
<cfhttpparam type="header" name="te" value="deflate;q=0">
<!--- pass in the xml-formatted request --->
<cfhttpparam type="xml" value="#trim(soapBody)#" />
</cfhttp>
<!--- if the status code is 200, we have a successful response --->
<cfscript>
if(find( "200", local.httpResponse.statusCode )) {
// Parse the XML --->
local.soapResponse = xmlParse( local.httpResponse.fileContent );
// Pull the specific nodes we need from the XML --->
local.responseNodes = xmlSearch(local.soapResponse, "//*[ local-name() = '#local.method#Result' ]");
// set to struct
local.strResult=ConvertXMLToStruct(local.responseNodes[1]);
// writeoutput('converted token response to structure<BR>');
// dump the response data --->
if(local.strResult.success) {
local.myAccessToken = local.strResult.UserAccountToken;
// writeoutput('access token acquired: #local.myAccessToken#<BR>');
} else {
// writeoutput('access token NOT acquired<BR>');
// stopanddump(arguments,0);
// stopanddump(local.strResult);
}
// set token to THIS scope
this.ICEtoken=local.myAccessToken;
}
</cfscript>
<!---
If I uncomment this:
<cfdump var="#local.myAccessToken">
<cfabort>
the dump shows the 172 character token
But, when trying to return this value, the calling function shows [empty string]
--->
<!--- return token --->
<cfreturn local.myAccessToken>
<cfcatch type="any"><cfdump var="#cfcatch#"><cfabort></cfcatch>
</cftry>
</cffunction>
If I hardcode a value such as
<cfreturn 'some 172 character string'>
this will successfuly return the value.
Any ideas?
Thanks
Upvotes: 0
Views: 1164
Reputation: 4701
I figured it out. It's not my code. It's the API pulling back a null value. The token I was outputting to begin with was a dummy account to initialize the CFC. I wasn't outputting the correct api call.
Upvotes: 0
Reputation: 14333
Your cfreturn
is invalid
<cfreturn myToken = webservice.struct.token>
If you want to return webservice.struct.token
Your cfreturn
should just be
<cfreturn webservice.struct.token>
Upvotes: 3