How can I pass the string “Null” through WSDL (SOAP) from ActionScript 3 to a ColdFusion web service without receiving a “missing parameter error”?
We have an employee whose last name is Null. He kills our employee lookup application when his last name is used as the search term (which happens to be quite often now). The error received (thanks Fiddler!) is 

Cute, huh?

The parameter's type is string.

I am using:

Note that the error DOES NOT occur when calling the webservice as an object from a ColdFusion page.
improve this question | comment
Hubert Reynolds V Created at: 2013-11-13 17:07:39 UTC By Hubert Reynolds V
10 Answers
It's a kludge, but assuming there's a minimum length for SEARCHSTRING, for example 2 characters, substring the SEARCHSTRING parameter at the second character and pass it as two parameters instead: SEARCHSTRING1 ("Nu") and SEARCHSTRING2 ("ll").  Concatenate them back together when executing the query to the database.
@doc_180 had the right concept, except he is focused on numbers, whereas the original poster had issues with strings.  

The solution is to change the mx.rpc.xml.XMLEncoder file. This is line 121 

    if (content != null)
        result += content;

[I looked at Flex 4.5.1 SDK; line numbers may differ in other versions]

Basically, the validation fails because 'content is null' and therefore your argument is not added to the outgoing SOAP Packet; thus causing the missing parameter error.  

You have to extend this class to remove the validation.  Then there is a big snowball up the chain, modifying SOAPEncoder to use your modified XMLEncoder, and then modifying Operation to use your modified SOAPEncoder, and then moidfying WebService to use your alternate Operation class.  

I spent a few hours on it, but need to move on.  It'll probably take a day or two.

You may be able to just fix the XMLEncoder line and do some monkey patching to use your own class.  

I'll also add that if you switch to using RemoteObject/AMF with ColdFusion, the null is passed without problems.
On the xkcd note, the Bobby Tables website has good advice for avoiding the improper interpretation of user data (in this case, the string "Null") in SQL queries in various languages, including ColdFusion.

It is not clear from the question that this is the source of the problem, and given the solution noted in a comment to the first answer (embedding the parameters in a structure) it seems likely that it was something else.
At first I thought this was a coercion bug where null was getting coerced to "null" and a test of "null" == null was passing. It's not. I was so, so very wrong. Sorry about that!

I've since done lots of fiddling and tracing through the code in mx.rpc.xml.*. At line 1795 of XMLEncoder (in the 3.5 source), in setValue, all of the XMLEncoding boils down to 


which finally, is the same as:


This code, according to my fiddle, returns an empty XML element.

Per my previous answer - the only good workaround I can think of is to test fields for "null" and escape them as CDATA values. This is better than hex-encoding, as it's more human readable. Further, this is the actual XML standard friendly way to mutate a text value that would otherwise cause encoding/decoding problems, as opposed to some of the other suggestions here.

Also, I'm editing my first bug report, FLEX-33644, to reflect my findings.
Translate all characters into their hex-entity equivalents. In this case, Null would be converted into &#4E;K&#6C;&#6C;
On the ActionScript 3.0 side add the following code:

if (lastname == 'null') 
    lastname = 'Little Bobby Tables';

Then in ColdFusion, the following:

if (lastname =='Little Bobby Tables') 
    lastname = 'null';

All fixed.
As a hack, you could consider having a special handling on the client side, converting 'Null' string to something that will never occur, for example, XXNULLXX and converting back on the server. 

It is not pretty, but it may solve the issue for such a boundary case.
If memory serves me correctly, stringifying a null value in actionscript will give the string "NULL".  My suspicion is that someone has decided that it is, therefore, a good idea to decode the string "NULL" as null, causing the breakage you see here -- probably because they were passing in null objects and getting strings in the database, when they didn't want that (so be sure to check for that kind of bug, too).
Well I guess that flex' implementation of the SOAP Encoder seems to serialize null values incorrectly. Serializing them as a String Null doesn't seem to be a good solution. The formally correct version seems to be to pass a null value as:
<childtag2 xsi:nil="true" />
So the value of "Null" would be nothing else than a valid string, which is exactly what you are looking for.

I guess getting this fixed in Apache Flex shouldn't be that hard to get done. I would recommend opening a Jira issue or to contact the guys of the apache-flex mailinglist. However this would only fix the client side. I can't say if ColdFusion will be able to work with null values encoded this way.
The problem could be in Flex' SOAP encoder. Try extending the SOAP encoder in your Flex application and debug the program to see how the null value is handled. My guess is, it's passed as NaN (Not a Number). This will mess up SOAP message unmarshalling process sometime (most notably in JBoss 5 server...). I remember extending the SOAP encoder and performing an explicit check on how NaN is handled. 

(On a side note, are you expected to do something useful if employee id is Null, is this not an validation issue? I could be wrong, since I hardly know the requirement...)
Your Answer