我有一个简单的cffunction,它调用webservice并返回一个令牌。 它已经工作了很长一段时间,但最近它什么都没有返回。
<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'>
这将成功返回价值。
有什么想法吗?
由于
答案 0 :(得分:3)
您的cfreturn
无效
<cfreturn myToken = webservice.struct.token>
如果您想返回webservice.struct.token
,则cfreturn
应该
<cfreturn webservice.struct.token>
答案 1 :(得分:0)
我明白了。这不是我的代码。这是API拉回空值。我输出的令牌是一个用于初始化CFC的虚拟帐户。我没有输出正确的api电话。