Skip to main content
Inspiring
September 27, 2011
Answered

Coldfusion invoke web service

  • September 27, 2011
  • 4 replies
  • 13049 views

I am trying to invoke a web service and I'm getting an error.

Error 401 Unauthorized.  Unable to read WSDL from URL: http://servername/generation/bj/TestCalculation.wsdl.  An exception occurred while invoking an event handler method from Application.cfc. The method name is: onRequest.

I can put the URL in the browser and it will pull up the WSDL. I can call this from a flex program and it will work fine.  I don't know much about Flex and I'm just learning it so I wanted to see if I could get it to work with ColdFusion.  

Here is the CFC I created:

    <cffunction name="myCalcFunction" access="remote" returntype="any">

            <cfinvoke

     webservice="http://servername/generation/bj/TestCalculation.wsdl"

     method="TestCalculation"

     returnvariable="response">

     <cfinvokeargument name="number1" value="#arguments.number1#"/>

     <cfinvokeargument name="number2" value="#arguments.number2#"/>

   </cfinvoke>

  <cfreturn response>

</cffunction>

Can anyone point me in the right direction of what I can do?

thanks for the support.

BJ

This topic has been closed for replies.
Correct answer BJ_-_CF

I think I found the problem but again I don't know how to solve it.  The program is working on my localhost but not on our dev server.  I checked and we aren't behind a proxy server.  The only difference between my localhost and my dev server is the dev server was on CF9.1 and my local was just at CF9.0.  I updated my local to 9.1 and now it is not working on my localhost and I'm getting the same error I was getting on my dev machine.  Something changed in 9.1. 

I want to try and go back to 9.0 on my dev and see if my program runs.  Is there anyway to back out the change or do I uninstall and reinstall 9?

Anyone else have problems on CF 9.1 like this.


Yes,  I finally found out it is a coldfusion 9.1 problem.    I uninstalled CF9.1 and installed CF8 and CF9.0 on my local machine.  I ran the web service code in both and it worked in both.  I then updated my CF9.0 to CF9.1.  I ran it again and it will give me the error.  This is running the same code with the same application.cfc.   Now I need to get Adobe to fix the problem.

BKBK, Adam, Dan and Owain,

   Thanks for the help on this.

BJ

4 replies

BJ_-_CFAuthor
Inspiring
September 30, 2011

OK, I got it to work on my CF local web server on my desk top.  But on the companies dev web server it gives me the error.  What would be giving me an Unauthorized error?

BKBK
Community Expert
Community Expert
September 30, 2011

My question about the access attribute?

BJ_-_CFAuthor
Inspiring
September 30, 2011

Yes, I got the same error when I changed it to public.  That is when I then tried to try it on my local and that part worked.

thanks,

bj

BKBK
Community Expert
Community Expert
September 30, 2011

BJ - CF wrote:

I am trying to invoke a web service and I'm getting an error.

Error 401 Unauthorized.

OK, I now notice the 401. That seems to be the main hint. Does it still occur when you change the access in the tag <cffunction name="myCalcFunction" access="remote" returntype="any"> from "remote" to "public"?

Inspiring
October 1, 2011

BKBK wrote:

BJ - CF wrote:

I am trying to invoke a web service and I'm getting an error.

Error 401 Unauthorized.

OK, I now notice the 401. That seems to be the main hint. Does it still occur when you change the access in the tag <cffunction name="myCalcFunction" access="remote" returntype="any"> from "remote" to "public"?

That was never a sensible suggestion.  One can't call a PUBLIC method as a web service (ie: REMOTEly).  Even if the web service is located on the same box, it's still being called remotely.

--

Adam

BKBK
Community Expert
Community Expert
October 3, 2011

Adam Cameron. wrote:

BKBK wrote:

BJ - CF wrote:

I am trying to invoke a web service and I'm getting an error.

Error 401 Unauthorized.

OK, I now notice the 401. That seems to be the main hint. Does it still occur when you change the access in the tag <cffunction name="myCalcFunction" access="remote" returntype="any"> from "remote" to "public"?

That was never a sensible suggestion.  One can't call a PUBLIC method as a web service (ie: REMOTEly).  Even if the web service is located on the same box, it's still being called remotely.

You misunderstand, Adam. That function appears to be the client (caller), not the server (web service). In any case, that was how I read it.

BKBK
Community Expert
Community Expert
September 30, 2011

BJ - CF wrote:

Error 401 Unauthorized.  Unable to read WSDL from URL: http://servername/generation/bj/TestCalculation.wsdl.  An exception occurred while invoking an event handler method from Application.cfc. The method name is: onRequest.

Comment out the onRequest method in Application.cfc. You may not use it when working with web services in this way

BJ_-_CFAuthor
Inspiring
September 30, 2011

I commented out the onRequest but it is still giving me the error.

thanks,

BJ

ruct
DetailError: 401 Unauthorized.
MessageUnable to read WSDL from URL: http://servername/generation/bj/TestCalculation.wsdl?wsdl.
StackTracecoldfusion.xml.rpc.XmlRpcServiceImpl$CantFindWSDLException: Unable to read WSDL from URL: http://servername/generation/bj/TestCalculation.wsdl?wsdl. at coldfusion.xml.rpc.XmlRpcServiceImpl.retrieveWSDL(XmlRpcServiceImpl.java:709) at coldfusion.xml.rpc.XmlRpcServiceImpl.access$000(XmlRpcServiceImpl.java:53) at coldfusion.xml.rpc.XmlRpcServiceImpl$1.run(XmlRpcServiceImpl.java:239) at java.security.AccessController.doPrivileged(Native Method) at coldfusion.xml.rpc.XmlRpcServiceImpl.registerWebService(XmlRpcServiceImpl.java:232) at coldfusion.xml.rpc.XmlRpcServiceImpl.getWebService(XmlRpcServiceImpl.java:496) at coldfusion.xml.rpc.XmlRpcServiceImpl.getWebServiceProxy(XmlRpcServiceImpl.java:450) at coldfusion.tagext.lang.InvokeTag.doEndTag(InvokeTag.java:449) at cfCalculateTwoNumbers2ecfc1061183910$funcMYCALCFUNCTION.runFunction(E:\Tristate\Generation\BJ\CalculateTwoNumbers.cfc:8) at coldfusion.runtime.UDFMethod.invoke(UDFMethod.java:472) at coldfusion.runtime.UDFMethod$ReturnTypeFilter.invoke(UDFMethod.java:405) at coldfusion.runtime.UDFMethod$ArgumentCollectionFilter.invoke(UDFMethod.java:368) at coldfusion.filter.FunctionAccessFilter.invoke(FunctionAccessFilter.java:55) at coldfusion.runtime.UDFMethod.runFilterChain(UDFMethod.java:321) at coldfusion.runtime.UDFMethod.invoke(UDFMethod.java:517) at coldfusion.runtime.TemplateProxy.invoke(TemplateProxy.java:496) at coldfusion.runtime.TemplateProxy.invoke(TemplateProxy.java:355) at coldfusion.runtime.CfJspPage._invoke(CfJspPage.java:2301) at coldfusion.tagext.lang.InvokeTag.doEndTag(InvokeTag.java:382) at cfCalculateTwoNumbers2ecfm1061183952.runPage(E:\Tristate\Generation\BJ\CalculateTwoNumbers.cfm:7) at coldfusion.runtime.CfJspPage.invoke(CfJspPage.java:231) at coldfusion.tagext.lang.IncludeTag.doStartTag(IncludeTag.java:416) at coldfusion.filter.CfincludeFilter.invoke(CfincludeFilter.java:65) at coldfusion.filter.ApplicationFilter.invoke(ApplicationFilter.java:360) at coldfusion.filter.RequestMonitorFilter.invoke(RequestMonitorFilter.java:48) at coldfusion.filter.MonitoringFilter.invoke(MonitoringFilter.java:40) at coldfusion.filter.PathFilter.invoke(PathFilter.java:94) at coldfusion.filter.ExceptionFilter.invoke(ExceptionFilter.java:70) at coldfusion.filter.BrowserDebugFilter.invoke(BrowserDebugFilter.java:79) at coldfusion.filter.ClientScopePersistenceFilter.invoke(ClientScopePersistenceFilter.java:28) at coldfusion.filter.BrowserFilter.invoke(BrowserFilter.java:38) at coldfusion.filter.NoCacheFilter.invoke(NoCacheFilter.java:46) at coldfusion.filter.GlobalsFilter.invoke(GlobalsFilter.java:38) at coldfusion.filter.DatasourceFilter.invoke(DatasourceFilter.java:22) at coldfusion.filter.CachingFilter.invoke(CachingFilter.java:62) at coldfusion.filter.RequestThrottleFilter.invoke(RequestThrottleFilter.java:126) at coldfusion.CfmServlet.service(CfmServlet.java:200) at coldfusion.bootstrap.BootstrapServlet.service(BootstrapServlet.java:89) at jrun.servlet.FilterChain.doFilter(FilterChain.java:86) at coldfusion.monitor.event.MonitoringServletFilter.doFilter(MonitoringServletFilter.java:42) at coldfusion.bootstrap.BootstrapFilter.doFilter(BootstrapFilter.java:46) at jrun.servlet.FilterChain.doFilter(FilterChain.java:94) at jrun.servlet.FilterChain.service(FilterChain.java:101) at jrun.servlet.ServletInvoker.invoke(ServletInvoker.java:106) at jrun.servlet.JRunInvokerChain.invokeNext(JRunInvokerChain.java:42) at jrun.servlet.JRunRequestDispatcher.invoke(JRunRequestDispatcher.java:286) at jrun.servlet.ServletEngineService.dispatch(ServletEngineService.java:543) at jrun.servlet.jrpp.JRunProxyService.invokeRunnable(JRunProxyService.java:203) at jrunx.scheduler.ThreadPool$DownstreamMetrics.invokeRunnable(ThreadPool.java:320) at jrunx.scheduler.ThreadPool$ThreadThrottle.invokeRunnable(ThreadPool.java:428) at jrunx.scheduler.ThreadPool$UpstreamMetrics.invokeRunnable(ThreadPool.java:266) at jrunx.scheduler.WorkerThread.run(WorkerThread.java:66)
BKBK
Community Expert
Community Expert
September 30, 2011
Owainnorth
Inspiring
September 27, 2011

Try adding ?wsdl at the end of the url, and do refreshwsdl=true to make sure it's not using an incorrectly cached interface.

BJ_-_CFAuthor
Inspiring
September 27, 2011

Owain,

  Thanks for the reply.  I added the two items but I get the same error message.

    <cffunction name="myCalcFunction" access="remote" returntype="any">

            <cfinvoke

     webservice="http://servername/generation/bj/TestCalculation.wsdl?wsdl"

     method="TestCalculation" refreshwsdl="true"

     returnvariable="response">

     <cfinvokeargument name="number1" value="#arguments.number1#"/>

     <cfinvokeargument name="number2" value="#arguments.number2#"/>

   </cfinvoke>

  <cfreturn response>

</cffunction>

Owainnorth
Inspiring
September 27, 2011

And the file extension of the webservice is definitely .wsdl? I've never seen that before. What technology is publishing it?

Webservices are also cached in CF Admin, so load up that and find the Webservices section - delete the cached WSDL if there is one for yours.