我的Flex code不解析SOAP响应正确 [英] My flex code does not parse the soap response properly

查看:299
本文介绍了我的Flex code不解析SOAP响应正确的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的code应该是解析SOAP响应和填充下拉列表。当我手动添加XML code它的工作原理,但是当我尝试分析它运行的SOAP响应到以下错误:

 类型错误:错误#1009:无法访问空对象引用的属性或方法。
在ex1_02_starter / dropDownList_creationCompleteHandler()[C:\用户\千斤顶\的Adobe Flash Builder 4.5中\工作区\入门1_02的\ src \ ex1_02_starter.mxml:26]
在ex1_02_starter / ___ ex1_02_starter_Operation1_result()[C:\用户\千斤顶\的Adobe Flash Builder 4.5中\工作区\入门1_02的\ src \ ex1_02_starter.mxml:41]
在flash.events::EventDispatcher/dispatchEventFunction()
在flash.events::EventDispatcher/dispatchEvent()
在mx.rpc::AbstractOperation/http://www.adobe.com/2006/flex/mx/internal::dispatchRpcEvent()[E:\dev\4.5.1\frameworks\projects\rpc\src\mx\rpc\AbstractOperation.as:249]
在mx.rpc::AbstractInvoker/http://www.adobe.com/2006/flex/mx/internal::resultHandler()[E:\dev\4.5.1\frameworks\projects\rpc\src\mx\rpc\AbstractInvoker.as:318]
在mx.rpc ::响应/结果()[E:\ dev的\ 4.5.1 \框架\项目\ RPC的\ src \ MX \ RPC \ Responder.as:56]
在mx.rpc::AsyncRequest/acknowledge()[E:\dev\4.5.1\frameworks\projects\rpc\src\mx\rpc\AsyncRequest.as:84]
在DirectHTTPMessageResponder/completeHandler()[E:\dev\4.5.1\frameworks\projects\rpc\src\mx\messaging\channels\DirectHTTPChannel.as:451]
在flash.events::EventDispatcher/dispatchEventFunction()
在flash.events::EventDispatcher/dispatchEvent()
在flash.net::URLLoader/onComplete()
 

SOAP响应,我接受

 < XML版本=1.0编码=UTF-8&GT?;
< soapenv:信封
  的xmlns:soapenv =htt​​p://schemas.xmlsoap.org/soap/envelope/
  的xmlns:XSD =htt​​p://www.w3.org/2001/XMLSchema的xmlns:XSI =htt​​p://www.w3.org/2001/XMLSchema-instance>
  < soapenv:身体与GT;
    < mycustomersResponse的xmlns =htt​​p://Services.com>
      < mycustomersReturn>
        <时代> 28 LT; /年龄>
        <名称>&亚历克斯LT; /名称>
      < / mycustomersReturn>
      < mycustomersReturn>
        <时代> 29< /年龄>
        <名称>杰克LT; /名称>
      < / mycustomersReturn>
      < mycustomersReturn>
        <时代> 30℃/年龄>
        <名称>&约翰尼LT; /名称>
      < / mycustomersReturn>
    < / mycustomersResponse>
  < / soapenv:身体与GT;
< / soapenv:信封>
 

我的Flex code

 < XML版本=1.0编码=UTF-8&GT?;
< S:应用的xmlns:FX =htt​​p://ns.adobe.com/mxml/2009
               XMLNS:S =库://ns.adobe.com/flex/spark
               的xmlns:MX =库://ns.adobe.com/flex/mx
               的xmlns:成分=组件*。
               的xmlns:打着招呼=services.hellos *。
               高度=957的creationComplete =initApp()>
    < FX:样式源=Styles.css中/>
    < FX:脚本>

        <![CDATA [
            进口mx.collections.XMLListCollection;
            进口mx.events.FlexEvent;
            进口mx.messaging.messages.SOAPMessage;
            进口mx.rpc.events.ResultEvent;
            [可绑定]
            VAR _result:*;
            私有函数initApp():无效
            {
                mywebservice.mycustomers();
            }
            保护功能
                dropDownList_creationCompleteHandler(事件:的ResultEvent):无效
            {
                VAR的xml:XML = event.result为XML;
                VAR的xmlString:字符串= xml.toXMLString();
                变种PATT:正则表达式=新的RegExp(的xmlns [^ \] * \[^ \] * \,GI);
                VAR newXmlString:字符串= xmlString.replace(PATT,);
                XML =新的XML(newXmlString);
                _result =新的XMLListCollection(xml.mycustomersResponse.mycustomersReturn);
            }

        ]]≥
    < / FX:脚本>
    < FX:声明>
    < S:WebService的ID =为MyWebService
                  WSDL =HTTP://本地主机:8081 / WebServiceTest的/服务/ Hello分组WSDL>
        < S:操作名称=mycustomers
                      的resultFormat =对象
                      结果=dropDownList_creationCompleteHandler(事件);
                      />
        < / S:WebService的>

    < / FX:声明>
    < S:FormItem中的标签=标签>
        < S:DropDownList的ID =DROPDOWNLIST

                        的labelField =名与GT;
            < S:AsyncListView列表={_结果}/>
        < / S:DropDownList的>
    < / S:的FormItem>
< / S:用途>
 

解决方案

从这里<一个未来href="http://stackoverflow.com/questions/14314467/dropdown-list-does-not-show-its-values/14319106#14319106">dropdown列表不显示其值我稍微修改我的例子。有两个机会:

  1. 从XML命名空间的条

  2. 利用空间

这些都显示在DROPDOWNLIST和dropDownList2 $ C $分别℃。

请注意,你不能还在使用labelField属性(至少我不能找到一种方法)利用空间。你必须使用的labelFunction提取标签。

 &LT; XML版本=1.0编码=UTF-8&GT?;
 

    

 &LT;![CDATA [
        进口mx.collections.XMLListCollection;
        进口mx.events.FlexEvent;
        进口mx.messaging.messages.SOAPMessage;
        [可绑定]
        VAR _result:*;
        [可绑定]
        VAR _result2:*;

        保护功能
            dropDownList_creationCompleteHandler(事件:FlexEvent):无效
        {
            VAR的xml:XML =&LT;车身及GT;
                            &LT; myusersResponse的xmlns =htt​​p://Services.com&GT;
                              &LT; myusersReturn&GT;
                                &LT;名称&gt;&妮可LT; /名称&gt;
                                &LT;时代&GT; 50℃/年龄&GT;
                              &LT; / myusersReturn&GT;
                              &LT; myusersReturn&GT;
                                &LT;名称&gt;&杰恩LT; /名称&gt;
                                &LT;时代&GT; 40℃/年龄&GT;
                              &LT; / myusersReturn&GT;
                               &LT; myusersReturn&GT;
                                &LT;名称&gt;&亚历克斯LT; /名称&gt;
                                &LT;时代&GT; 33&LT; /年龄&GT;
                              &LT; / myusersReturn&GT;
                            &LT; / myusersResponse&GT;
                          &LT; /身体取代;


            VAR的xmlString:字符串= xml.toXMLString();
            变种PATT:正则表达式=新的RegExp(的xmlns [^ \] * \[^ \] * \,GI);
            VAR newXmlString:字符串= xmlString.replace(PATT,);
            XML =新的XML(newXmlString);
            _result =新的XMLListCollection(xml.myusersResponse.myusersReturn);

        }

        保护功能dropDownList2_creationCompleteHandler(事件:FlexEvent):无效
        {
            VAR的xml:XML =&LT;车身及GT;
                            &LT; myusersResponse的xmlns =htt​​p://Services.com&GT;
                              &LT; myusersReturn&GT;
                                &LT;名称&gt;&妮可LT; /名称&gt;
                                &LT;时代&GT; 50℃/年龄&GT;
                              &LT; / myusersReturn&GT;
                              &LT; myusersReturn&GT;
                                &LT;名称&gt;&杰恩LT; /名称&gt;
                                &LT;时代&GT; 40℃/年龄&GT;
                              &LT; / myusersReturn&GT;
                               &LT; myusersReturn&GT;
                                &LT;名称&gt;&亚历克斯LT; /名称&gt;
                                &LT;时代&GT; 33&LT; /年龄&GT;
                              &LT; / myusersReturn&GT;
                            &LT; / myusersResponse&GT;
                          &LT; /身体取代;

            VAR NS:命名空间=新的命名空间(http://Services.com);
            _result2 =新的XMLListCollection(xml.ns :: myusersResponse.ns :: myusersReturn);
        }

        私有函数dropDownList2_labelFunction(项目:对象):字符串{
            VAR itemXml:XML =项目作为XML;
            VAR NS:命名空间=新的命名空间(http://Services.com);
            返回item.ns ::名称;
        }

    ]]≥
&LT; / FX:脚本&GT;

&LT; FX:声明&GT;

&LT; / FX:声明&GT;

&LT; S:FormItem中的标签=标签&GT;
    &LT; S:DropDownList的ID =DROPDOWNLIST
                    的creationComplete =dropDownList_creationCompleteHandler(事件)
                    的labelField =名与GT;
        &LT; S:AsyncListView列表={_结果}/&GT;
    &LT; / S:DropDownList的&GT;
    &LT; S:DropDownList的ID =dropDownList2
                    的creationComplete =dropDownList2_creationCompleteHandler(事件)
                    的labelFunction =dropDownList2_labelFunction&GT;
        &LT; S:AsyncListView列表={_ RESULT2}/&GT;
    &LT; / S:DropDownList的&GT;
&LT; / S:的FormItem&GT;
 

My code is supposed to parse a SOAP response and populate the dropdown list. When I manually add the xml code it works but when I try to parse the SOAP response it runs into following error:

TypeError: Error #1009: Cannot access a property or method of a null object reference.
at ex1_02_starter/dropDownList_creationCompleteHandler()[C:\Users\jack\Adobe Flash Builder 4.5\Workspace\Starter 1_02\src\ex1_02_starter.mxml:26]
at ex1_02_starter/___ex1_02_starter_Operation1_result()[C:\Users\jack\Adobe Flash Builder 4.5\Workspace\Starter 1_02\src\ex1_02_starter.mxml:41]
at flash.events::EventDispatcher/dispatchEventFunction()
at flash.events::EventDispatcher/dispatchEvent()
at mx.rpc::AbstractOperation/http://www.adobe.com/2006/flex/mx/internal::dispatchRpcEvent()[E:\dev\4.5.1\frameworks\projects\rpc\src\mx\rpc\AbstractOperation.as:249]
at mx.rpc::AbstractInvoker/http://www.adobe.com/2006/flex/mx/internal::resultHandler()[E:\dev\4.5.1\frameworks\projects\rpc\src\mx\rpc\AbstractInvoker.as:318]
at mx.rpc::Responder/result()[E:\dev\4.5.1\frameworks\projects\rpc\src\mx\rpc\Responder.as:56]
at mx.rpc::AsyncRequest/acknowledge()[E:\dev\4.5.1\frameworks\projects\rpc\src\mx\rpc\AsyncRequest.as:84]
at DirectHTTPMessageResponder/completeHandler()[E:\dev\4.5.1\frameworks\projects\rpc\src\mx\messaging\channels\DirectHTTPChannel.as:451]
at flash.events::EventDispatcher/dispatchEventFunction()
at flash.events::EventDispatcher/dispatchEvent()
at flash.net::URLLoader/onComplete()

The SOAP Response that I am receiving

  <?xml version="1.0" encoding="UTF-8"?>
<soapenv:Envelope
  xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
  xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  <soapenv:Body>
    <mycustomersResponse xmlns="http://Services.com">
      <mycustomersReturn>
        <age>28</age>
        <name>Alex</name>
      </mycustomersReturn>
      <mycustomersReturn>
        <age>29</age>
        <name>Jack</name>
      </mycustomersReturn>
      <mycustomersReturn>
        <age>30</age>
        <name>Johny</name>
      </mycustomersReturn>
    </mycustomersResponse>
  </soapenv:Body>
</soapenv:Envelope>

My Flex code

<?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"
               xmlns:components="components.*"
               xmlns:hellos="services.hellos.*"
               height="957"  creationComplete="initApp()" > 
    <fx:Style source="Styles.css"/>
    <fx:Script>

        <![CDATA[
            import mx.collections.XMLListCollection;
            import mx.events.FlexEvent;
            import mx.messaging.messages.SOAPMessage;
            import mx.rpc.events.ResultEvent;
            [Bindable]
            var _result:*;
            private function initApp():void
            {
                mywebservice.mycustomers();
            }
            protected function  
                dropDownList_creationCompleteHandler(event:ResultEvent):void
            {
                var xml:XML = event.result as XML;
                var xmlString:String = xml.toXMLString();
                var patt:RegExp = new RegExp("xmlns[^\"]*\"[^\"]*\"", "gi");
                var newXmlString:String = xmlString.replace(patt, "");
                xml = new XML(newXmlString);
                _result = new XMLListCollection(xml.mycustomersResponse.mycustomersReturn);
            }

        ]]>  
    </fx:Script>
    <fx:Declarations>
    <s:WebService id="mywebservice"
                  wsdl="http://localhost:8081/WebServiceTest/services/Hellos?wsdl">
        <s:operation name="mycustomers"
                      resultFormat="object"
                      result="dropDownList_creationCompleteHandler(event);"
                      />
        </s:WebService>

    </fx:Declarations>
    <s:FormItem label="Label">
        <s:DropDownList id="dropDownList"

                        labelField="name">
            <s:AsyncListView list="{_result}"/>
        </s:DropDownList>  
    </s:FormItem>
</s:Application>

解决方案

coming from here dropdown list does not show its values I slightly modified my example. There are two opportunities:

  1. Strip namespace from xml

  2. Utilize namespace

Those are shown in dropDownList and dropDownList2 code respectively.

Note, that you can not utilize namespace still using labelField property(at least I couldn't find a way). You have to use labelFunction to extract label.

<?xml version="1.0" encoding="utf-8"?>

    <![CDATA[
        import mx.collections.XMLListCollection;
        import mx.events.FlexEvent;
        import mx.messaging.messages.SOAPMessage;
        [Bindable]
        var _result:*;
        [Bindable]
        var _result2:*;

        protected function  
            dropDownList_creationCompleteHandler(event:FlexEvent):void
        {
            var xml:XML = <Body>
                            <myusersResponse xmlns="http://Services.com">
                              <myusersReturn>
                                <name>Nicole</name>
                                <age>50</age>
                              </myusersReturn>
                              <myusersReturn>
                                <name>Jayne</name>
                                <age>40</age>
                              </myusersReturn>
                               <myusersReturn>
                                <name>Alex</name>
                                <age>33</age>
                              </myusersReturn>
                            </myusersResponse>
                          </Body>;


            var xmlString:String = xml.toXMLString();
            var patt:RegExp = new RegExp("xmlns[^\"]*\"[^\"]*\"", "gi");
            var newXmlString:String = xmlString.replace(patt, "");
            xml = new XML(newXmlString);
            _result = new XMLListCollection(xml.myusersResponse.myusersReturn);

        }

        protected function dropDownList2_creationCompleteHandler(event:FlexEvent):void
        {
            var xml:XML = <Body>
                            <myusersResponse xmlns="http://Services.com">
                              <myusersReturn>
                                <name>Nicole</name>
                                <age>50</age>
                              </myusersReturn>
                              <myusersReturn>
                                <name>Jayne</name>
                                <age>40</age>
                              </myusersReturn>
                               <myusersReturn>
                                <name>Alex</name>
                                <age>33</age>
                              </myusersReturn>
                            </myusersResponse>
                          </Body>;

            var ns:Namespace = new Namespace("http://Services.com");
            _result2 = new XMLListCollection(xml.ns::myusersResponse.ns::myusersReturn);                
        }

        private function dropDownList2_labelFunction(item:Object):String{
            var itemXml:XML = item as XML;
            var ns:Namespace = new Namespace("http://Services.com");
            return item.ns::name;
        }

    ]]> 
</fx:Script>

<fx:Declarations>

</fx:Declarations>

<s:FormItem label="Label">
    <s:DropDownList id="dropDownList"
                    creationComplete="dropDownList_creationCompleteHandler(event)"
                    labelField="name">
        <s:AsyncListView list="{_result}"/>
    </s:DropDownList>
    <s:DropDownList id="dropDownList2"
                    creationComplete="dropDownList2_creationCompleteHandler(event)"
                    labelFunction="dropDownList2_labelFunction">
        <s:AsyncListView list="{_result2}"/>
    </s:DropDownList>       
</s:FormItem>

这篇关于我的Flex code不解析SOAP响应正确的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆