web-servicescoldfusionwsdlcfinvoke

Coldfusion WSDL IllegalArgumentException on cfinvokeargument


When you are calling a method of a webservice and want to omit an unrequired numeric variable that has a default value set coldfusion will throw the following error:

The fault returned when invoking the web service operation is:<br>
<pre>'' java.lang.IllegalArgumentException</pre>

Example:

<cfinvoke
    webservice = "http://*.cfc?WSDL" 
    method="getFriendlyDay" 
    returnvariable="response"
    refreshWSDL="true"
>
        <cfinvokeargument name="dayNumber" omit="true"/>
</cfinvoke>

webservice component:

<cffunction name="getFriendlyDay" access="remote" returntype="any" output="no" description="get a friendly date from a number">   

        <cfargument name="dayNumber" type="numeric" required="no" default="0">
        ...
</cffunction>

Solution

  • My solution to this is to just not omit the argument. Pass in the default value. I just wanted to record this in case someone else gets the same error. Thus far it has only occurred on numeric values.

    <cfinvoke
        webservice = "http://*.cfc?WSDL" 
        method="getFriendlyDay" 
        returnvariable="response"
        refreshWSDL="true"
    >
            <cfinvokeargument name="dayNumber" value="0" >
    </cfinvoke>
    

    Update:

    I believe this probably relates to the bug outlined here:

    The way Coldfusion handles optional arguments as a remote service is that it allows the calling client to pass in a null value. In a document/literal or rpc/encoded WSDL description, an element can accept null unless it specifies "nillable='false'". The generated WSDLs from Coldfusion do not use "nillable='false'" or "minOccurs='0'" which instructs the client that they must include the parameter and that it is ok to pass in a null value.

    The problem however is that "numeric" or "boolean" argument types that are optional will throw an "Illegal Argument Exception" when being called by a client who is trying to explicitly pass in null ...