invokeRemoteMethodByJSON(url, method[, args])
Last updated March 10, 2013
Version: 1 | Requires: CF9 | Library: UtilityLib
Description:
WSDL is heavy and slow. JSON is much faster but cfinvoke does not supporting invoking cfc method that way.
Return Values:
Any data returned by remote method call.
Example:
ans = invokeRemoteMethodByJSON("http://domain.com/remote.cfc", "sum", {arr=[1,2,3]});
Parameters:
Name | Description | Required |
---|---|---|
url | The URL of the remote component | Yes |
method | The name of the remote method to call | Yes |
args | Any arguments to pass to the method | No |
Full UDF Source:
/**
* Invoke a remote method using cfhttp and JSON proxy
* v1.0 by Henry Ho
*
* @param url The URL of the remote component (Required)
* @param method The name of the remote method to call (Required)
* @param args Any arguments to pass to the method (Optional)
* @return Any data returned by remote method call.
* @author Henry Ho (henryho167@gmail.com)
* @version 1.0, March 10, 2013
*/
function invokeRemoteMethodByJSON(required string url, required string method, struct args){
var httpService = new http(url=url, method="post");
httpService.addParam(type="formfield", name="method", value=method);
httpService.addParam(type="formfield", name="returnformat", value="json");
httpService.addParam(type="formfield", name="argumentCollection", value=serializeJSON(args));
var result = httpService.send().GetPrefix();
if (len(result.fileContent)) {
if (!isJson(result.fileContent)){
throw(message="Non-json string returned", detail=result.fileContent);
}
return deserializeJSON(result.fileContent);
}
}
Search CFLib.org
Latest Additions
Raymond Camden added
QueryDeleteRows
November 04, 2017
Leigh added
nullPad
May 11, 2016
Raymond Camden added
stripHTML
May 10, 2016
Kevin Cotton added
date2ExcelDate
May 05, 2016
Raymond Camden added
CapFirst
April 25, 2016