Copy link to clipboard
Copied
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
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
Copy link to clipboard
Copied
Try adding ?wsdl at the end of the url, and do refreshwsdl=true to make sure it's not using an incorrectly cached interface.
Copy link to clipboard
Copied
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>
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
Yes, the extenstion is WSDL. We are using a product called NextAxiom. It is a middleware software. I can use the web service in Adobe Flex and it will call this same WSDL and work fine. That is why I'm thinking it is something with CF. I'm not sure why I'm getting an unauthorized error since it works in Flex.
Copy link to clipboard
Copied
Can you browse to the wsdl file and see the xml?
Copy link to clipboard
Copied
Yes, I can browse the WSDL and it brings back the XML fine.
thanks for the reply.
BJ
Copy link to clipboard
Copied
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
Copy link to clipboard
Copied
I commented out the onRequest but it is still giving me the error.
thanks,
BJ
ruct | |
---|---|
Detail | Error: 401 Unauthorized. |
Message | Unable to read WSDL from URL: http://servername/generation/bj/TestCalculation.wsdl?wsdl. |
StackTrace | coldfusion.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) |
Copy link to clipboard
Copied
Your URL should be http://servername/generation/bj/TestCalculation.cfc?wsdl or shouldn't it?
Copy link to clipboard
Copied
No, I'm invoking the webservice from the CFC and the webservice URL should be point at my WSDL file.
Copy link to clipboard
Copied
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"?
Copy link to clipboard
Copied
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
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
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?
Copy link to clipboard
Copied
My question about the access attribute?
Copy link to clipboard
Copied
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
Copy link to clipboard
Copied
Then it probably just means what it says. The machine hosting the web service requires the machine calling the service to first obtain permission.
So the problem is still one of access. But then, at the level of client and server. What is the situation about permissions, allowed IPs, login, etc. on the machine hosting the service?
Copy link to clipboard
Copied
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?
Because the URL you're requesting requires authorisation before you can access it:
http://en.wikipedia.org/wiki/HTTP_401#4xx_Client_Error
What happens if you just browse to the URL in a web browser. I imagine you get a login prompt?
--
Adam
Copy link to clipboard
Copied
If I put the URL in the browser, which is the WSDL, it will bring up the XML file fine and doesn't prompt me.
BJ
Copy link to clipboard
Copied
If I put the URL in the browser, which is the WSDL, it will bring up the XML file fine and doesn't prompt me.
OK, cool. Now... what if you call the method via the browser?
update:
Oh, and are you browsing that URL from the CF server, or your own PC?
--
Adam
Message was edited by: Adam Cameron.
Copy link to clipboard
Copied
Here is my process:
I tried to run it on our dev machine and that is when I get the 401 error that we talked about. I got it to work on the dev machine with Flex and web services (no ColdFusion call). Now I wanted to try it with ColdFusion. I couldn't get it to work with coldFusion on dev so I tried to see if I can run it from my local machine. Yes, it works on my local CF web server. I have a .cfm file that accepts two numbers and when you submit it, it will call the cfc with the invoke. The result of the two numbers should come back. It should call this web service I created to add them together. So now I have it working on my local but my questions is what or where do I look to get it to run on the company's web server (dev)?
On the dev server I put the CFC in the browser and it came back and asked for the RDS password. Adam is this what you meant when you said to call the method via the browser? Here is the info it put out after I entered the password:
Generation.BJ.CalculateTwoNumbers
Component CalculateTwoNumbers
hierarchy: | WEB-INF.cftags.component Generation.BJ.CalculateTwoNumbers |
path: | E:\Tristate\Generation\BJ\CalculateTwoNumbers.cfc |
serializable: | Yes |
properties: | |
methods: | myCalcFunction |
* - private method
myCalcFunction |
---|
public any myCalcFunction ( ) Output: |
thanks for the replies,
BJ
Copy link to clipboard
Copied
BJ - CF, I am a bit confused now. Which one is the web service, CalculateTwoNumbers.cfc or TestCalculation.wsdl? On which machine is the web service, and from which machine are you attempting to invoke the web service?
What happens when you create a test CFM page, and run the following code
<cfinvoke
webservice="http://servername/generation/bj/TestCalculation.wsdl"
method="TestCalculation"
returnvariable="response">
<cfinvokeargument name="number1" value="1"/>
<cfinvokeargument name="number2" value="2"/>
</cfinvoke>
<cfdump var="#response#">
Copy link to clipboard
Copied
Sorry for the confusion.
I changed my code to just call the cfinvoke from the cfm program.
BJ
Copy link to clipboard
Copied
BJ - CF, just to finally clear things up:
1) What is the name of the CFC (or WSDL) of the web service?
(My assumption was that TestCalculation is the web service. However, you say in your last post that TestCalculation is just an XML to call the web service.)
2) On which machine is the web service located: on localhost, on Dev or on some other machine?