java - 无法从 Flex 中的 java Web 服务响应检索值

标签 java apache-flex web-services actionscript

我正在尝试从flex mxml/action脚本中读取java web服务中的数据,似乎调用即请求/响应成功,但是当无法从响应中读取值时,请帮助MXML代码如下:

Unable to print the value from :
var outA:OutputA_type = ccxc.OutputA;
 trace(outA);
var aaa:String = outA.toString();
Alert.show(aaa)

它打印为[Object OutputA)_Type],但不是所需的值。然而,在 Flex 构建器测试连接以及网络监控中,我看到了正确的值/响应。

<?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:number1="services.number1.*"
               xmlns:testws="services.testws.*"
               minWidth="955" minHeight="850" creationComplete="initApp()">


    <!-- Styles ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -->

    <fx:Style source="Styles.css"/>

    <!-- Script ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -->

    <fx:Script>
        <![CDATA[
            import mx.collections.ArrayCollection;
            import mx.collections.ArrayList;
            import mx.controls.Alert;
            import mx.events.CalendarLayoutChangeEvent;
            import mx.rpc.AsyncToken;
            import mx.rpc.events.FaultEvent;
            import mx.rpc.events.ResultEvent;
            import mx.utils.ObjectUtil;

            import services.testws.Testws;

            import valueObjects.OutputA_type;
            import valueObjects.Parameters_type;
            import valueObjects.TestParameters;
            import valueObjects.TestResult_type;

            private function initApp():void  {

                var testWebS:Testws = new Testws();
                var testParam:TestParameters = new TestParameters();
                testParam.ParamA = 2;
                testParam.ParamB = 3;

                var token:AsyncToken = testWebS.test(testParam);

                token.addResponder(new mx.rpc.Responder(result, fault));
            }

            private function result(event:ResultEvent) : void {
                trace(event.result);
                var strData:TestResult_type = event.result as  TestResult_type;
                var ccxc:Parameters_type = strData.Parameters;
                var outA:OutputA_type = ccxc.OutputA;
                trace(outA);
                var aaa:String = outA.toString();

                Alert.show(aaa.toString());

            }

            public function fault(event : FaultEvent) : void {
                Alert.show("Failed Condition Fault Exception");
            }

        ]]>
    </fx:Script>

    <!-- Declarations ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -->

    <fx:Declarations>

    </fx:Declarations>

    <!-- UI components ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -->

    <s:Label x="10" y="34" 
             width="690" height="40" 
             text="Employee Portal: Vehicle Request Form"
             styleName="titleHeader"/>

    <s:Form x="10" y="70">
        <s:FormItem label="Input a:">
            <s:TextInput id="a"/>
        </s:FormItem>
        <s:FormItem label="Input b:">
            <s:TextInput id="b"/>
        </s:FormItem>
        <s:FormItem>
            <s:Button id="submitButton" 
                      label="Submit Request" click="submitButton_clickHandler(event)"/>
        </s:FormItem>
    </s:Form>

</s:Application>


SOAP-UI Request:
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:tes="http://tempuri.org/testws">
   <soapenv:Header/>
   <soapenv:Body>
      <tes:test>
         <tes:parameters>
            <!--Optional:-->
            <tes:ParamA>3</tes:ParamA>
            <!--Optional:-->
            <tes:ParamB>1</tes:ParamB>
         </tes:parameters>
      </tes:test>
   </soapenv:Body>
</soapenv:Envelope>

SOAP-UI Response:
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
   <soapenv:Body>
      <m:testResponse xmlns:m="http://tempuri.org/testws">
         <m:testResult>
            <axis2ns794:Parameters xmlns:axis2ns794="http://tempuri.org/testws">
               <axis2ns795:OutputA description="" xmlns:axis2ns795="http://tempuri.org/testws">1</axis2ns795:OutputA>
            </axis2ns794:Parameters>
         </m:testResult>
      </m:testResponse>
   </soapenv:Body>
</soapenv:Envelope>

最佳答案

而不是使用

 private function result(event:ResultEvent) : void {
            trace(event.result);
            var strData:TestResult_type = event.result as  TestResult_type;
            var ccxc:Parameters_type = strData.Parameters;
            var outA:OutputA_type = ccxc.OutputA;
            trace(outA);
            var aaa:String = outA.toString();

            Alert.show(aaa.toString());

        }

尝试使用对象而不是直接转换它。

var retObj:Object = event.result;
var strData:TestResult_type = new TestResult_type();
strData.firstProperty = retObj.firstProperty;
strData.secondProperty = retObj.secondProperty;

我想我之前遇到过这个问题,你不能像在java端那样将返回的对象分配给flex对象。如果这有效,那么您必须遍历每个 event.result 对象并通过 setter 设置对象的所有属性。

关于java - 无法从 Flex 中的 java Web 服务响应检索值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7501036/

相关文章:

c# - 如何编写自己的基于XmlService 的ORM?

ios - 将数据从 iOS 标签字段发送到网站文本字段

c# - 使用 C# 和 WFC 的跨域 jQuery Ajax

java - 对应用程序上下文的引用是否会泄漏我保留的 fragment ?

java - 从 PHP MySql 填充 Android spinner

java - 如何在路由器表达式中使用 util 常量?

java - 使用 Flex Monkey 和 Selenium 自动化 Flex 应用程序的步骤

apache-flex - 使用 AS3 读取简单的 INI 文件

php - 使用 PHP 作为后端的 Flex Remoting 问题

java - 对参数传递感到困惑