How can I call a rest component in ColdFusion? I create the file test.cfc.
component displayName="Test" rest="true" restPath="Test" {
public any function method1(data) access="remote" httpmethod="GET" returnformat="JSON" {
...
}
}
This file is located: root/myApp/components/test.cfc
I tried to open by: https://mytestsite.com/myApp/components/Test
However, it returns error 404 - Not Found
Please find the YouTube link to a tutorial using CF Rest and Angular.
https://youtu.be/4GkXanOqH88
Below is link to sample code on CF Rest
https://github.com/mayuranchalia/DeveloperWeek
localhost:8500/rest/(restmapping)/Test
Rest mapping you provide when registering the service in ColdFusion Administrator.
https://www.adobe.com/devnet/coldfusion/articles/restful-web-services.html
Related
I'm trying to integrate ColdFusion version 2016 application with SharePoint. I have a ColdFusion app that is trying to access a csv file on a SharePoint site. I'm able to access the csv file on SharePoint when I pass in the URL into a browser, but unable to access it from CF. I tried several different combinations of the tag but keep getting one of the following errors:
1) '401 UNAUTHORIZED'
2) Error: org.apache.http.conn.HttpHostConnectException: Connect to
DomainName:80
(Note: In the second error, I masked the actual domain name for security purposes).
I confirmed with the SharePoint admin that the domain name, username and password are set up correctly and he did confirm the same. Has anyone tried this type of integration and run into the same issues, and how was it solved?
Code for a couple of the combinations of cfsharepoint that I tried is below:
Using cfscript:
<cfscript>
loginStruct = {domain="xxxxx", username="abc123", password="xyz$566",authtype="ntlm", wsdl="https://mywebsite.com/sites/xxx-Home/_vti_bin/Lists.asmx?wsdl"};
cfsharepoint(action="getlistcollection", login=loginStruct, name="myResult");
writeDump(myResult);
//writeDump(loginStruct);
</cfscript>
Using :
<cfsharepoint action="getlistcollection"
WSDL="https://mywebsite.com/sites/xxx-Home/LED_Docs/Forms/AllItems.aspx?WSDL"
username="abc123"
domain="xxxx"
password="xyz$566"
name="listCollection"/>
authtype="NTLM"
<CFDUMP var="#listCollection#">
Running ColdFusion 10 Update 18 on Server 2012 R2 with IIS 8.5. I've made changes to a CFC, and created a new CFC file as well to test. The changes I made aren't being reflected, and the new file returns a 404 File Not Found.
I've done the following:
Checked the Jakarta virtual directory exists
Removed and readded the site with the CF Web Config tool
Cleared the WEB-INF class temporary folder
Clicked all the Clear Cache buttons in CF Admin
Unchecked all cache options in CF Admin
I inherited this setup and do not have any prior ColdFusion experience. Thanks!
Maybe you can add some supplemental functionality to your application.
I adapted this to your fw1init=1 query param.
Your intercept in index.cfm or futher upstream if necessary.
<cfscript>
if (find('404;',CGI.query_string)){
location('index.cfm?fwreinit=1');
}
</cfscript>
In your Application.cfc
<cfscript>
public boolean function OnRequestStart(required string Target){
if (structkeyExists(url, 'fwreinit') and url.fwreinit){
if (isDefined('application')){
structClear(application);
onApplicationStart();
}
if (isDefined('session')){
structClear(session);
onSessionStart();
}
}
}
</cfscript>
I am trying to consume the following web service from ColdFusion:
http://xserv.dell.com/services/assetservice.asmx
I should be able to consume the web service using the code below:
<cfscript>
params = structNew();
params.guid = "11111111-1111-1111-1111-111111111111";
params.applicationName = "test";
params.serviceTags = "JLJMHX1";
ws = createObject("webservice", "http://xserv.dell.com/services/assetservice.asmx?wsdl");
writeDump(ws)
ws.GetAssetInformation(params);
</cfscript>
The results of dumping out the WSDL information (ws), indicates that the GetAssetInformation method has the following signature:
getAssetInformation(com.microsoft.wsdl.types.Guid, java.lang.String, java.lang.String)
The service call errors every single time, saying that:
"Error Occurred While Processing Request
Web service operation GetAssetInformation with parameters {11111111-1111-1111-1111-111111111111,test,JLJMHX1} cannot be found."
I am sure this is due to the method expecting a "com.microsoft.wsdl.types.Guid" data type, but how can I pass that in via ColdFusion?
I can create and run the request in Fiddler with the same data and get a response back without issue, so there is something I am doing wrong in ColdFusion.
Any help would be appreciated.
The method expects a guid and two strings. You are passing a structure. Pass the arguments separately.
ColdFusion 10 also introduces Axis 2 for web services by default. For some web services, you need to use Axis 1 which you can enable in the ColdFusion Administrator. You will also need to refresh the web service.
createObject("webservice", theURL, {refreshWSDL=true,wsVersion=1})
I found the answer by following the instructions in this post:
Consume SOAP web service having complex types
Thanks for the help everyone!
I am testing consuming a web-service and I'm getting an error.
Here is the web-service component:
<cfcomponent >
<cffunction name="listBooks" access="remote" returntype="string" output="no" >
<cfquery name="getBooks" datasource="cfbookclub" >
SELECT bookID, title, bookDescription, genre
FROM books
ORDER BY title desc
</cfquery>
<cfsavecontent variable="bookList" >
<books>
<cfoutput query="getBooks" >
<book id="#getBooks.bookID#" >
<title>#XMLFormat( getBooks.title )#</title>
<description>#XMLFormat( getBooks.bookDescription )#</description>
<genre>#XMLFormat( getBooks.genre )#</genre>
</book>
</cfoutput>
</books>
</cfsavecontent>
<cfreturn bookList >
</cffunction>
Here is the consuming page:
<cfinvoke
webservice="http://127.0.0.1/books.cfc?wsdl"
method="listBooks"
returnvariable="rawXMLBookList" >
</cfinvoke>
Seems simple enough - I was actually trying to pass an argument "genre" when I got the initial error,
Web service parameter name category cannot be found in the provided parameters {genre}.
So I removed all reference to arguments, and STILL get this error
Web service operation with parameters {} cannot be found.
The error makes it sound like the web-service cannot be found, however if I cut and paste the url into my browser I get the expected XML doc...
There was another post like this on this site, but the problem was a base64 issue, I'm just returning txt so I don't think it's a similar problem, even through the error msg is similar.
Try adding the refreshWSDL argument to your <cfinvoke> call and see if that helps.
<cfinvoke
webservice="http://127.0.0.1/books.cfc?wsdl"
method="listBooks"
refreshwsdl="yes"
returnvariable="rawXMLBookList">
</cfinvoke>
Setting refreshwsdl="yes" reloads the WSDL file and regenerates the artifacts used to consume the web service.
Note you do not want to keep this setting for all of your requests. You just need to set it for one request to refresh the artifacts. Then you should change it back to refreshwsdl="no". Until you need it again.
Here is an excerpt from Charlie Arehart's Blog about the refreshWSDL argument:
Why should you have to refresh the web service metadata?
Just to back up for a moment, the problem stems from CF's attempt to help. On the first request for a given web service, CF does some caching to make future requests go faster, not caching the results of the web service method but rather the artifacts used by CF based on the description of the web service itself.
CF uses the web service description (WSDL) reported at the time of that first call to create a java proxy/stub based on that, which it then reuses on future calls from CF to that web service.
The issue arises if/when the web service metadata changes. CF won't know, and will continue to use the older cached proxy/stub, and your long-running code may fail if it doesn't match the new WSDL returned by the web service.
So we need a way to tell CF to refresh its cache of that proxy stub.
This new feature is certainly the easiest way to make that happen, but it's not the only way.
I am trying to call a webservice from my Flex application and this is the code:
<mx:WebService id="myWebService"
wsdl="http://172.16.111.103:22222/cics/services/PRESENT1?wsdl">
<mx:operation name="PRESENT1Operation"
result="resultHandler(event)"
fault="faultHandler(event)">
</mx:operation>
</mx:WebService>
//Function to send customer id to the wsdl request
private function searchDetails():void{
myWebService.PRESENT1Operation.send(cusNo.text);
cusDetails.visible=true;
}
The webservice is up and running. I have a separate Java application to test the webservice, And I am able to execute it properly. I am able to request the webservice and get response.
But If I try to call the webservice through the Flex application, I get the following error.
[RPC Fault faultString="HTTP request error" faultCode="Server.Error.Request" faultDetail="Unable to load WSDL. If currently online, please verify the URI and/or format of the WSDL (http://172.16.111.103:22222/cics/services/PRESENT1?WSDL)"]
at mx.rpc.wsdl::WSDLLoader/faultHandler()[C:\autobuild\3.2.0\frameworks\projects\rpc\src\mx\rpc\wsdl\WSDLLoader.as:98]
at flash.events::EventDispatcher/dispatchEventFunction()
at flash.events::EventDispatcher/dispatchEvent()
at mx.rpc::AbstractInvoker/http://www.adobe.com/2006/flex/mx/internal::dispatchRpcEvent()[C:\autobuild\3.2.0\frameworks\projects\rpc\src\mx\rpc\AbstractInvoker.as:170]
at mx.rpc::AbstractInvoker/http://www.adobe.com/2006/flex/mx/internal::faultHandler()[C:\autobuild\3.2.0\frameworks\projects\rpc\src\mx\rpc\AbstractInvoker.as:225]
at mx.rpc::Responder/fault()[C:\autobuild\3.2.0\frameworks\projects\rpc\src\mx\rpc\Responder.as:53]
at mx.rpc::AsyncRequest/fault()[C:\autobuild\3.2.0\frameworks\projects\rpc\src\mx\rpc\AsyncRequest.as:103]
at DirectHTTPMessageResponder/errorHandler()[C:\autobuild\3.2.0\frameworks\projects\rpc\src\mx\messaging\channels\DirectHTTPChannel.as:362]
at flash.events::EventDispatcher/dispatchEventFunction()
at flash.events::EventDispatcher/dispatchEvent()
at flash.net::URLLoader/redirectEvent()
Please some one help me with this.
The application is unable to load as the application starts before the other modules can be loaded
I hope this might be useful
var wsdlFile :String = <>
var request:URLRequest = new URLRequest(wsdlFile);
var loader:URLLoader = new URLLoader();
loader.load(request);
You can get the complete path by typing in the URL append it with ?wsdl