我有一个简单的 cffunction 调用 web 服务并返回一个令牌。它已经工作了很长一段时间,但最近它什么也没返回。
<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>
如果我硬编码一个值,例如
<cfreturn 'some 172 character string'>
这将成功返回值。
有任何想法吗?
谢谢