本文介绍了如何传递“Null"(真正的姓氏!)到 ActionScript 3 中的 SOAP Web 服务的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们有一位姓氏为 Null 的员工.当该姓氏用作搜索词时,我们的员工查找应用程序就会被终止(现在这种情况很常见).收到的错误(感谢 Fiddler!)是:

We have an employee whose surname is Null. Our employee lookup application is killed when that last name is used as the search term (which happens to be quite often now). The error received (thanks Fiddler!) is:

<soapenv:Fault>
   <faultcode>soapenv:Server.userException</faultcode>
   <faultstring>coldfusion.xml.rpc.CFCInvocationException: [coldfusion.runtime.MissingArgumentException : The SEARCHSTRING parameter to the getFacultyNames function is required but was not passed in.]</faultstring>

可爱吧?

参数类型为string.

我正在使用:

  • WSDL (SOAP)
  • Flex 3.5
  • 动作脚本 3
  • ColdFusion 8

请注意,当从 ColdFusion 页面将网络服务作为对象调用时,不会发生错误.

Note that the error does not occur when calling the webservice as an object from a ColdFusion page.

推荐答案

追踪

起初我以为这是一个强制错误,其中 null 被强制为 "null" 并且测试了 "null" == null正在通过.它不是.我很接近,但非常非常错误.抱歉!

Tracking it down

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 close, but so very, very wrong. Sorry about that!

从那以后我做了很多在wonderfl.net上摆弄并跟踪mx.rpc.xml.*.在 XMLEncoder 的第 1795 行(在 3.5 源代码中),在 setValue 中,所有的 XMLEncoding 都归结为

I've since done lots of fiddling on wonderfl.net 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

currentChild.appendChild(xmlSpecialCharsFilter(Object(value)));

本质上是一样的:

currentChild.appendChild("null");

根据我原来的小提琴,这段代码返回一个空的 XML 元素.但为什么?

This code, according to my original fiddle, returns an empty XML element. But why?

原因

根据评论者 Justin Mclean 在错误报告 FLEX-33664 上的评论,以下内容是罪魁祸首(请参阅我的 fiddle 中的最后两个测试来验证这一点):

According to commenter Justin Mclean on bug report FLEX-33664, the following is the culprit (see last two tests in my fiddle which verify this):

var thisIsNotNull:XML = <root>null</root>;
if(thisIsNotNull == null){
    // always branches here, as (thisIsNotNull == null) strangely returns true
    // despite the fact that thisIsNotNull is a valid instance of type XML
}

currentChild.appendChild 传递字符串 "null" 时,它首先将其转换为带有文本 null 的根 XML 元素,然后然后针对空文字测试该元素.这是一个弱相等性测试,因此要么将包含 null 的 XML 强制转换为 null 类型,要么将 null 类型强制转换为包含字符串null"的根 xml 元素,并且测试通过了它可能会失败的地方.一种解决方法可能是始终使用 严格相等在检查 XML(或任何东西,真的)nullness"时进行测试.

When currentChild.appendChild is passed the string "null", it first converts it to a root XML element with text null, and then tests that element against the null literal. This is a weak equality test, so either the XML containing null is coerced to the null type, or the null type is coerced to a root xml element containing the string "null", and the test passes where it arguably should fail. One fix might be to always use strict equality tests when checking XML (or anything, really) for "nullness."

解决方案

我能想到的唯一合理的解决方法,除了在每个该死的 ActionScript 版本中修复这个错误之外,是测试字段是否为null"并将它们转义为 CDATA 值.

Solution

The only reasonable workaround I can think of, short of fixing this bug in every damn version of ActionScript, is to test fields for "null" and escape them as CDATA values.

CDATA 值是改变整个文本值的最合适方法,否则会导致编码/解码问题. 例如,十六进制编码用于单个字符.当您转义元素的整个文本时,首选 CDATA 值.这样做的最大原因是它保持了人类的可读性.

CDATA values are the most appropriate way to mutate an entire text value that would otherwise cause encoding/decoding problems. Hex encoding, for instance, is meant for individual characters. CDATA values are preferred when you're escaping the entire text of an element. The biggest reason for this is that it maintains human readability.

这篇关于如何传递“Null"(真正的姓氏!)到 ActionScript 3 中的 SOAP Web 服务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-25 00:18