Creating Webservices with Variable Arguments and Other Gotcha's in Coldfusion

Coldfusion makes building webservices very easy. You can quickly create a component and set the function you wish expose by setting the function access to remote and you are done!


Webservices are a bit quirky though and what worked as a component call won’t always work as a webservice call. Below are some of the issues I had to work though. Hopefully this saves time for someone else.

Webservice functions cannot have optional arguments.

Unlike a function call in a component, all arguments must be passed in a webservice call. If you do not pass the exact number of arguments with the correct type you will get an error that looks something like this:

coldfusion.xml.rpc.ServiceProxy$ServiceMethodNotFoundException: Web service operation getItems with parameters {} cannot be found

I was once building a webservice to search on multiple terms and for a moment was faced with the prospect that I would need to build multiple versions of the same function to search on a single term, or two, or three, etc. The solution to this problem is for your webservice to take a single structure as its only argument.



Inside the myArguments structure you can now pass as many or few values as you’d like.

If you’ve built your webservice as a public facade for an underlying service you can now just pass your webservice argument struct to that service as the argumentCollection. The service layer can then work normally and have multiple optional arguments if you’d like since it will receive the webservice’s single structure argument as its argumentCollection.




Webservices are cached in the Coldfusion Administrator

This is not an issue once the webservice is deployed, but during development you may find that your code updates don’t seem to be changing anything. This is because the old wsdl information of the webservice gets cached in the CFadmin. You must log into CFAdmin and manually delete it from the webservice registry. It will re-register itself once you use it again.

Webservices have data limitations that Coldfusion Components do not have

My co-worker & I were once getting an error from a webservice that was making us pull our hair out. The function worked fine when called as a component, but once called as a webservice the same data would throw this error:

The fault returned when invoking the web service operation is:AxisFault faultCode: { http://schemas.xmlsoap.org/soap/envelope/ }Server.userException faultSubcode: faultString: java.lang.NumberFormatException: Invalid date fault

Eventually we discovered that in the test data there was a date with a value of “9999” for the year. This date is not out of range for Coldfusion, but when the call is converted to a webservice the date is out of range for Apache Axis and the request puked.