I tried creating a web service in ColdFusion, for that I just created a component with a function inside it having access="remote"
<cfcomponent displayname="testPost" hint="testing.." output="yes">
<cfsetting enablecfoutputonly="true" showdebugoutput="true">
<cffunction access="remote" output="true" name="testPostReq" displayname="testPostReq" description="testing" returntype="any">
<cfset p=9>
<cfreturn p>
</cffunction>
</cfcomponent>
Now I wanted to call this webservice and I am trying to hit this in my browser, https://sampleapp.xyz.com/DirectoryToCfc/CfcName.cfc?wsdl but in browser I am getting "Unsupported Operation. Check application log for more details." when I checked application logs I saw this log there:
"Warning","ajp-bio-8013-exec-4","09/27/21","12:57:55","COMPONENTUTILS","To use Component Browser, enable RDS Service using Administrator. Note: RDS is intended for development use only."
How can I deal with this, any idea? Is it possible to do without enabling RDS?
Please let me know if you know something about this, I will be really grateful.
You can create a webservice for WSDL. Here I'm going to taken an some real time demo url http://www.dneonline.com/calculator.asmx?wsdl & Coldfusion 2018. Please follow the below steps.
Step 1 : Create webservice in CFAdmin - > Data & Service - > Webservices
Step 2 : Give the Webservice name & WSDL URL value. Refer my image here (TestService.png) I've created 'TestService' for the url http://www.dneonline.com/calculator.asmx?wsdl.
Step 3 : Once you added it successfully. You can able to see that in "Active Coldfusion WebService Options"
Step 4 : With the help of createObject method & webservice value you can call your all methods in your WSDL url. For example,
<cfset myObj = createObject('webservice','TestService')>
<cfdump var='#myObj#' abort="true">
Step 5 : You can see my below dump about demo webservice url Methods & Classes. Refer image dumpService.png
I hope this will help you to know about simple Webservice.
Related
We recently migrated our site from application.CFM to application.CFC. The CFM version could handle our excessive bot traffic, but our CFC version can't. We are trying to figure out why the CFC problem is. In the meantime, we are trying to limit bot traffic.
Currently, I am looking for a solution within the code base to slow bot traffic. We can do this by looking at the user agent as well as IP address.
We have used the code below to successfully stop many bots.
<cffunction name="OnRequestStart">
<cfif find("bot", cgi.httP_USER_AGENT)>
<cfabort>
</cfif>
</cffunction>
Obviously, we do want some bot traffic. But right now, we can't handle all of the bot traffic. It appears that as soon as we you abort to stop a request, another request is right behind it and eventually they bring down our server.
Instead of stopping the bots, what would the ramifications be of using CFTHREAD to slow the bots?
<cffunction name="OnRequestStart">
<cfif find("bot", cgi.httP_USER_AGENT)>
<cfthread action="sleep" duration="5"></cfthread>
</cfif>
</cffunction>
Would using CFTHREAD just stack up the requests and eventually kill our server or would the bots respond with fewer requests per hour?
I've been running into some challenges with a web service I'm trying to use of from ColdFusion. The service (AccountsService), has a method, GetAccountLinksByUser that returns accounts associated with a given user. This method accepts two arguments:
UPN, which is just a unique string to identify the user. This is no problem, as far as I can tell.
sourceType. This is ultimately a string, but is defined in the WSDL as simple type with one of three possible values. Here's a relevant sections of XML from the WSDL:
<xsd:simpleType name="SourceType">
<xsd:restriction base="xsd:string">
<xsd:enumeration value="All"/>
<xsd:enumeration value="Manual"/>
<xsd:enumeration value="System"/>
</xsd:restriction>
</xsd:simpleType>
The problem is that I can't seem to just pass the string "All", "Manual", or "System" into the web service. The stub that CF generates has the following signature for this method:
getAccountLinksByUser(java.lang.String, org.datacontract.schemas._2004._07.tfonline_services_accounts_datacontracts.SourceType)
This appears to suggest that I need to pass in an instance of org.datacontract.schemas._2004._07.tfonline_services_accounts_datacontracts.SourceType. However, I can't create an instance of that type (easily) as it doesn't appear to be in a class path that CF searches. I tried wrapping the classes that CF generates into the /stubs directory into a jar and putting them in a class path. This did work, in that I could now create an instance of org.datacontract.schemas._2004._07.tfonline_services_accounts_datacontracts.SourceType, but I was still unable to pass that into the getAccountLinksByUser method.
As requested, here is the code I'm using to call the web service:
<cfset accountsService = CreateObject("WebService", "http://local.hostname/libraries/com/foo/bar/staging/AccountsService.wsdl") />
<cfset SourceType = CreateObject("java", "org.datacontract.schemas._2004._07.tfonline_services_accounts_datacontracts.SourceType") />
<cfset accounts = accountsService.getAccountLinksByUser("username#domain", SourceType.All) />
More information. The publisher of the web service does not publish their WSDL publicly. This was emailed to me and I'm loading the WSDL from my my local development site.
The specific error I'm getting is:
Cannot perform web service invocation getAccountLinksByUser.
The fault returned when invoking the web service operation is:
Cannot perform web service invocation getAccountLinksByUser. The fault
returned when invoking the web service operation is: ''
java.lang.IllegalArgumentException: argument type mismatch
I'm not really sure where to head at this point. Any suggestions?
The service is written in .NET.
I ran a few tests and it seems related to the switch to Axis2 in CF10. I am honestly not sure exactly what about enumeration's changed between 1 and 2. However, setting the version level back to Axis1 should do the trick:
<cfscript>
args = { refreshWSDL=true, wsversion=1 };
ws = createObject("webservice", "http://mysite/test.asmx?wsdl", args);
result = ws.getAccountLinksByUser("test#somewhere.com", "All");
writeDump(result);
</cfscript>
I'm on Windows 2008 R2 (64-bit) using CF10 (64-bit) (developer edition?)
I am trying to implement this very basic tutorial:
http://blogs.coldfusion.com/post.cfm/rest-support-in-coldfusion-part-i
I created a new website through IIS on port 8081 and then added two files:
/index.cfm (in theory, since no application.cfc containing app vars was needed, I could have skipped this)
<cfset s = "Hello World!">
<cfoutput>#s#</cfoutput>
/RestExample/HelloWorld.cfc
<cfcomponent rest="true" restPath="/hello">
<cffunction name="sayHello" access="remote" returnType="String" httpMethod="GET">
<cfset res="Hello World">
<cfreturn res>
</cffunction>
</cfcomponent>
In CF Admin:
Root Path: C:/websites/test/RestExample/
Service Mapping: Example
I get the following error:
Error registering REST service. Please ensure that you have entered a proper mapping and path.
Application Example could not be initialized.
Reason: The application does not contain any rest enabled CFCs.
The application does not contain any rest enabled CFCs.
A bit of system information:
Server Product ColdFusion
Version 10,0,8,284032
Tomcat Version 7.0.23.0
Edition Developer
Serial Number Developer
Operating System Windows Server 2008 R2
OS Version 6.1
Update Level /C:/ColdFusion10/cfusion/lib/updates/chf10000008.jar
Adobe Driver Version 4.1 (Build 0001)
JVM Details
Java Version 1.6.0_29
Java Vendor Sun Microsystems Inc.
Java Vendor URL http://java.sun.com/
Java Home C:\ColdFusion10\jre
Not sure if it's a configuration issue at this point? This is related to my previous question, and trying to simplify everything to isolate the cause.
Edit #1
I was able to add a this very simple RESTful service to a Windows 7 64-bit / CF 10 (no updates) without any issues. I wonder if it's my install that is corrupt or the update that corrupted it?
Edit #2
I reinstalled my CF server and it still gave me the same issue.
Edit #3
As per milanchandna's suggestions, I followed these steps:
Created a folder c:\websites\milanchandna
Created a new website (milanchandna using the apppool with the same name) in IIS and used c:\websites\milanchandna as root, running on port 8084
Created jakarta virtual directory (need this)
Added basic HelloWorld.cfc
Navigated to HelloWorld.cfc with success, no errors
In CF Admin, REST Services, added the following:
Root Path: C:/websites/milanchandna/
Service mapping: Example
Click Add Service
Get error:
Error registering REST service. Please ensure that you have entered a proper mapping and path.
Application Example could not be initialized.
Reason: The application does not contain any rest enabled CFCs.
The application does not contain any rest enabled CFCs.
HelloWorld.cfc:
<cfcomponent rest="true" restPath="/hello">
<cffunction name="sayHello" access="remote" returnType="String" httpMethod="GET">
<cfset res="Hello World">
<cfreturn res>
</cffunction>
</cfcomponent>
I created the files under C:\ColdFusion10\cfusion\wwwroot (instead of the site's IIS root) and was able to register the REST service via the administration console without any issue.
As this is a basic example not working, I will suggest to follow it from starting.
Create a fresh new folder in IIS webroot. This should not be inside any folder already being used for CF REST.
Just put one simple rest cfc in this folder and nothing else. The CFC example given in your problem description looks good, let's use that.
Access this CFC from browser as you would access any cfm
eg:[http://mysite:8081/mypath_to_cfc/mycfc.cfc]
Check if this throws any error. If it does, then there is a problem in CFC. If it doesn't then you are good to go.
Register this folder as REST application from administrator.
On CF 9.01, Windows Web Server 2008 R2, a web service has stopped running here, so I'm trying to figure out the problem. I think the problem may have started when I applied the 9.01 hotfix.
I added a test.cfc to the server
<cfcomponent output="false">
<cffunction
name = "echoString"
output = "no"
access = "remote" returntype="any">
<cfargument required="true" name="inputString" type="string"/>
<cfreturn arguments.inputString>
</cffunction>
</cfcomponent>
and call it with
<cfinvoke webservice="https://nww.somedomain.nhs.uk/cfcs/test.cfc?wsdl"
method="echoString" returnvariable="returnedString">
<cfinvokeargument name="inputString" value="test string 2">
</cfinvoke>
and get the string response, but in the cf administrator the web service is not being added
when I invoke the web service for the first time as I think it should be.
Other than reinstalling CF or trying to roll back manually, any clues as to the problem or how I can test please?
I'm on 9,0,1,274733 . The https is not the problem I think. Firstly it was working fine then with no change to code it stopped. Secondly my test invocation of test.cfc works as expected over https.
If I hit https://nww.somedomain.nhs.uk/cfcs/test.cfc?wsdl (which works) or my problem cfc https://nww.somedomain.nhs.uk/cfcs/providerapi.cfc?wsdl directly in the browser they both correctly show the XML details.
However, invoking either of the CFCs does not add them to the active web services list in administrator.
I pasted the "echostring" method to my problem CFC (providerapi.cfc) and tried calling the method but I get a "webservice cannot be found" error. It's like the providerapi.cfc is cached , but I can't see it in administrator to delete it.
I tried this verbatim on 9,0,1,274733 and it worked 100% fine. I am using Win 7 and I just tried it on my dev environment. The web service was added to the list in CF admin so you are correct to expect that.
Can you ensure that you can hit the URL direct (i.e. https://nww.somedomain.nhs.uk/cfcs/test.cfc?wsdl) in your browser and view source to see the WSDL XML?
One thing that jumps out is the use of https:// in your web service invocation. Can you try it with just http:// or even better against your localhost?
I have a web service setup for on a small part of a website and while the site overall gets a good amount of traffic this particular service does not. Once a day when I go to send a request through the web service it will fail on the first attempt, but retrying the request a second time works just fine. It's as if it was no longer cached in memory and times out while starting up.
Is there a way to keep this service active either on my end or on the web service provider's end which is also CF app (separate division of our company)? It's a bit hard to troubleshoot because it only happens once after a long period. And I don't want to setup a separate process just to keep pinging this service.
If the server is being restarted regularly between calls to the template, ensure the "save class files" setting is enabled in the administrator (under caching) to prevent the template from being recompiled after each server reload.
You can try to use following method on a webservice client side.
CF7+ got built-in coldfusion.server.ServiceFactory Java service.
Code can look like
<cftry>
<!--- here goes attempt to invoke service method, maybe dummy "ping" --->
<cfcatch type="any">
<!--- trying to refresh WSDL --->
<cfset createObject("java","coldfusion.server.ServiceFactory").XmlRpcService.refreshWebService(ServiceURL) />
</cfcatch>
</cftry>
<!--- usual code --->
Hope this helps.
Note: this factory contains a lot of useful methods, but almost zero documentation over the internet. Good idea would be to dump it and explore a bit.
Try increasing the requesttimeout and see if that helps.