Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
556 views
in Technique[技术] by (71.8m points)

apache-flex - 如何在ActionScript 3中将“ Null”(真实的姓氏!)传递给SOAP Web服务(How to pass “Null” (a real surname!) to a SOAP web service in ActionScript 3)

We have an employee whose surname is Null. (我们有一个姓为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: (收到的错误(感谢Fiddler!)是:)

<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>

Cute, huh? (可爱吧?)

The parameter type is string . (参数类型为string 。)

I am using: (我在用:)

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

Note that the error does not occur when calling the webservice as an object from a ColdFusion page. (请注意,从ColdFusion页面将Webservice作为对象调用时,不会发生该错误。)

  ask by bill translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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. (起初,我认为这是一个强制错误,其中null被强制为"null"并且测试"null" == null已通过。) It's not. (不是。) I was close, but so very, very wrong. (我很近,但是非常非常错误。) Sorry about that! (对于那个很抱歉!)

I've since done lots of fiddling on wonderfl.net and tracing through the code in mx.rpc.xml.* . (从那以后,我在wonderfl.net上做了很多摆弄,并在mx.rpc.xml.* 查找了代码。) At line 1795 of XMLEncoder (in the 3.5 source), in setValue , all of the XMLEncoding boils down to (在XMLEncoder第1795 XMLEncoder (在3.5源代码中),在setValue ,所有XMLEncoding都归结为)

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

which is essentially the same as: (本质上与以下内容相同:)

currentChild.appendChild("null");

This code, according to my original fiddle, returns an empty XML element. (根据我的原始提琴,此代码返回一个空的XML元素。) But why? (但为什么?)

Cause (原因)

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): (根据关于bug报告FLEX-33664的评论员Justin Mclean 的说法 ,以下是罪魁祸首(请参阅我的小提琴中的最后两个测试,以验证这一点):)

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
}

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. (当将currentChild.appendChild传递给字符串"null" ,它将首先将其转换为文本为null的根XML元素,然后针对null文字对该元素进行测试。) 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. (这是一个弱等式测试,因此将包含null的XML强制转换为null类型,或者将null类型强制转换为包含字符串“ null”的根xml元素,并且该测试通过,可能会失败。) One fix might be to always use strict equality tests when checking XML (or anything, really) for "nullness." (一种解决方法是在检查XML(或其他任何东西)是否为“空”时始终使用严格的相等性测试。)

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 . 除了在每个可恶的ActionScript版本中修复此错误之外,我能想到的唯一合理的解决方法是测试字段是否为“ null”并将其作为CDATA值进行转义。)

CDATA values are the most appropriate way to mutate an entire text value that would otherwise cause encoding/decoding problems. (CDATA值是变异整个文本值的最合适方法,否则将导致编码/解码问题。) Hex encoding, for instance, is meant for individual characters. (例如,十六进制编码是针对单个字符的。) CDATA values are preferred when you're escaping the entire text of an element. (转义元素的整个文本时,首选CDATA值。) The biggest reason for this is that it maintains human readability. (这样做的最大原因是它保持了人类可读性。)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...