I am trying to read data from the java web service from flex mxml/action script, seems like the call i.e request/response is successfully but when unable to read the value from the response, please help the MXML code is as below:
Unable to print the value from :
var outA:OutputA_type = ccxc.OutputA;
trace(outA);
var aaa:String = outA.toString();
Alert.show(aaa)
it prints as [Object OutputA)_Type]
but not the required value. however in the flex builder test connection also in the network monitoring I see the proper value/response.
<?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&开发者_运维知识库gt;
</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>
Instead of using
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());
}
try using Object instead of casting it directly.
var retObj:Object = event.result;
var strData:TestResult_type = new TestResult_type();
strData.firstProperty = retObj.firstProperty;
strData.secondProperty = retObj.secondProperty;
I think I had an issue with this before where you can't just assign the returned object to a flex object like you can on the java side. If this works then you have to go through each of the event.result objects and set all of the properties of your object through setters.
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());
}
- What is the response you get while doing
trace(event.result)
- Do a trace of this strData, post down what you get.
精彩评论