@doc_180 的概念是正确的,只是他专注于数字,而最初的发帖人则存在字符串问题。
解决方法是更改mx.rpc.xml.XMLEncoder 文件。这是第 121 行:
if (content != null)
result += content;
(我查看了 Flex 4.5.1 SDK;其他版本的行号可能不同。)
基本上,验证失败是因为“内容为空”,因此您的参数没有添加到传出的 SOAP 数据包中;从而导致缺少参数错误。
您必须扩展此类以删除验证。然后是一个大雪球,修改 SOAPEncoder 以使用您修改后的 XMLEncoder,然后修改 Operation 以使用您修改后的 SOAPEncoder,然后修改 WebService 以使用您的备用 Operation 类。
我花了几个小时在上面,但我需要继续前进。可能需要一两天时间。
您也许可以只修复 XMLEncoder 行并做一些monkey patching 以使用您自己的类。
我还要补充一点,如果您切换到将 RemoteObject/AMF 与 ColdFusion 一起使用,则 null 可以毫无问题地传递。
2013 年 11 月 16 日更新:
我在上一条关于 RemoteObject/AMF 的评论中添加了一个最新内容。如果您使用的是 ColdFusion 10;然后从服务器端对象中删除对象上具有空值的属性。因此,您必须在访问之前检查属性是否存在,否则会出现运行时错误。
像这样检查:
<cfif (structKeyExists(arguments.myObject,'propertyName')>
<!--- no property code --->
<cfelse>
<!--- handle property normally --->
</cfif>
这是 ColdFusion 9 的行为变化;其中 null 属性将变成空字符串。
2013 年 12 月 6 日编辑
由于存在关于如何处理空值的问题,这里有一个快速示例应用程序来演示字符串“null”如何与保留字 null 相关。
<?xml version="1.0" encoding="utf-8"?>
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx" minWidth="955" minHeight="600" initialize="application1_initializeHandler(event)">
<fx:Script>
<![CDATA[
import mx.events.FlexEvent;
protected function application1_initializeHandler(event:FlexEvent):void
{
var s :String = "null";
if(s != null){
trace('null string is not equal to null reserved word using the != condition');
} else {
trace('null string is equal to null reserved word using the != condition');
}
if(s == null){
trace('null string is equal to null reserved word using the == condition');
} else {
trace('null string is not equal to null reserved word using the == condition');
}
if(s === null){
trace('null string is equal to null reserved word using the === condition');
} else {
trace('null string is not equal to null reserved word using the === condition');
}
}
]]>
</fx:Script>
<fx:Declarations>
<!-- Place non-visual elements (e.g., services, value objects) here -->
</fx:Declarations>
</s:Application>
跟踪输出为:
使用 != 条件的空字符串不等于空保留字
使用 == 条件的空字符串不等于空保留字
使用 === 条件的空字符串不等于空保留字