Using XML in Flex - Tutorial Part 4 - WebService
Flex provides an ActionScript 3.0 class named WebService and a MXML component named WebService. My references for this tutorial are the Adobe Flex 2 Language Reference, Programming ActionScript 3.0, and the Flex 2 Developer's Guide.
The WebService class and component can be used to access SOAP-based web services. For more information on SOAP-based web services see: http://www.w3schools.com/soap/default.asp.
WebService Class
Let's examine the ActionScript 3.0 WebService class first and provide an example of how to use it. The WebService class exposes several properties and methods. One of the more important properties is wsdl, which is the location of the Web Service Description Language (WSDL) document for the web service. The WSDL document details the services provided by the web service, what inputs are required to use the service, and what outputs the service returns. A detailed description of WSDL is here: http://www.w3.org/TR/wsdl.
My example for this tutorial uses the USZip WebService provided by www.webservicex.net
To use the WebService class you will need this information:
- WSDL - for example http://www.webservicex.net/uszip.asmx?wsdl
- Method Name - for example GetInfoByCity
- Method Parameters - for example USCity
- NameSpace (if you want results formatted in e4x XML) - for example http://www.webserviceX.NET (see page 1150 in Flex 2.0 Developer's Guide)
If you examine the WSDL and the SOAP envelope returned you can find the information needed above. The USZip webservice has four methods we can use. In my example I use the GetInfoByCity method. You provide this method the name of a US city and it returns an XML document with the city, state, zip, area code, and time zone. If you examine the complete results returned, you will see that the response specifies an XML namespace of http://www.webserviceX.NET. To properly use the results formatted in e4x XML, you will need to create a namespace object and use it in your Flex app (see page 1150 in the Flex 2.0 Developer's Guide).
After you've created the WebService object, you specify the values for its properties, such as WSDL and resultFormat (e4x). You also specify which functions will handle the result and fault events by using your object name.the webservice method name.addEventListener(...). For example:
WS.GetInfoByCity.addEventListener("result", resultHandler);
The above code specifies that a function named resultHandler will handle the result event for method GetInfoByCity.
One of the event handlers you specify is for the load event. The load event is triggered when the WebService has completed loading the WSDL. Inside the function you specified as handling the load event is where you can call the WebService method. You pass any arguments to the WebService's methods inside the parenthesis:
//call the WebService method GetInfoByCity
WS.GetInfoByCity(city.selectedLabel);
In the above, I'm sending to the WebService method the user's selection in the city combo box.
In the resultHandler function I refer to the XML returned by the webservice method using the dot notation I discussed in tutorial 1.
WS.GetInfoByCity.lastResult is the XML document returned
WS.GetInfoByCity.lastResult.GetInfoByCityResult.NewDataSet.Table[0].ZIP gets the value for the ZIP node that is a child of the first Table element that is a child of the NewDataSet element, that is a child of the GetInfoByCityResult element.
To view the example click here. You can right click on the example to view the source code.
mx:WebService MXML Tag
Instead of the ActionScript 3.0 WebService class you can use the WebService MXML tag. When you use the mx:WebService tag you specify the WSDL and the id value (used to refer to the component later). Inside the mx:WebService tag you use an mx:operation tag to identify the webservice method you want to use and the resultFormat for the data returned by the method. Inside the mx:operation tag you use an mx:request tag to specify the values for the method's parameters. The elements inside the mx:request tag should be named to match the parameter names specified by the webservice method.
To make the call to the webservice method, you use the id value.the method name.send(). For example:
WS.GetInfoByCity.send() (where WS is the id value for the mx:WebService component)
Once the results are returned by the webservice you can bind them to various MXML components. Again you can use the dot notation to get the value of a specific element. You can also use the XML returned to populate a DataGrid.
See the mx:WebService example and right click on it to view the source.
Please post any suggestions for improving this tutorial or questions about areas that I've not properly covered.


WS.addEventListener("load", loadHandler);
was key for me; I'd missed this in the Flex docs.
One thing I would add in an example is something that I am using for my project....how to send the URL of a web service, using flashvars, into the Flex project. This way, the service is not hard-coded in the project. I couldn't really get this working right using MXML, so I switched to defining the web service in ActionScript.
Basically just
private var myWebServiceURL:String;
and then in InitApp()
myWebServiceURL = Application.application.parameters.webServiceURL;
And finally in the UseWebService() method
MyService.wsdl = myWebServiceURL + "WSDL";
Good idea. I'll try that next.
But, this article solved it.
Thank you.
I'm a newbie within Flash..I'm currently working with Flash CS3...
I have some questions:
Can i use the code with Flash CS3 a well?
What alternative exists to e4x?
I have a asp.net 2.0 website...which is going to communicate/pass a variable to the action script code(eg. by java script)...which then is going to call a webservice...but how do i call the webservice method: action script code file --> (call) method in the mxml file which then call the real webservice...? how does that looks like?
Please be kind - it is my first flash app! :)
Cheers
Pablo
See the area in my tutorial where I call a webservice in ActionScript.
I have looked at your example...made my own dot net web service, which is very simple...the method is called HelloWorld and is just returning a string (it does not take any in parameters)...and it is working very wel!! :)
This is how my returned XML looks like:
<HelloWorldResponse xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://www.123.dk/" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">...;
<HelloWorldResult>Pablo has problems!</HelloWorldResult>
</HelloWorldResponse>
My question to you is:
How do I get/fetch the text "Pablo has problems!" from the XML??
I have tried for so many hours now and it should be VERY simple!
The DOC says: webservice.method.lastResult.Property;
Which gives:
WS.HelloWorld.lastResult.HelloWorldResult;
I really hope that you can help me on this one, i'm so close this time ;)
Best,
Pablo
var ws:WebService = new WebService();
ws.wsdl = "http://weblogs.macromedia.com/mxna/webservices/mxn...;;
ws.useProxy = false;
ws.getMostPopularPosts.addEventListener("result", doResultHandler);
ws.getMostPopularPosts.request =<request><daysBack>30</daysBack><limit>5</limit></request>*/;
ws.addEventListener("fault",faultHandler);
ws.getMostPopularPosts();
ws.loadWSDL();
ws.getMostPopularPosts.send();
<soap12:body>
<method>
<someParameter attrube0="int" atribute1="string" attibutex="Boolean"/>
<otherParameter>String</otherParameter>
</method>
</soap12:body>
I can not pass someParameter as object or xml then it throwes a HTTP request error. If pass it as xmlString or String. then I get a new error back from the server.
"Error #1069: Property attrube0 not found on String and there is no default value."
I hope that there is a sollution to pass xml with attributes
As above. When I try to send an Object with SOAP I get a (Error #2032: Stream Error) error. The crossdomain.xml is ok. And i can use the webservice when I only pass single values like int or string. Is it some kind of serialization error? Is there a way to tell the SOAP how to serialize?
Cheers,
Adam
myChart.getData.lastResult.toXMLString()
<getDataResponse xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns="http://tempuri.org/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">...;
<getDataResult>
<int>45</int>
<int>65</int>
<int>2</int>
</getDataResult>
</getDataResponse>
Can you pls tell me how can i bind the
<int>45</int>
<int>65</int>
<int>2</int>
to a pie chart or data Grid Single col..i have tried doing it the following way but it brings emty grid and empty chart
For data Grid
=====================================================
<mx:DataGrid dataProvider="{myChart.getData.lastResult.getDataResult}">
<mx:columns>
<mx:DataGridColumn dataField="int" headerText="Random Nos"/>
</mx:columns>
</mx:DataGrid>
For Pie Chart
====================================================
<mx:PieChart id="chart" showDataTips="true" dataProvider="{myChart.getData.lastResult.getDataResult}" >
<mx:series>
<mx:PieSeries labelPosition="callout" field="int"></mx:PieSeries>
</mx:series>
</mx:PieChart>
Pls help me on this
private namespace webXNameSpace = "http://tempuri.org/";
use namespace webXNameSpace;
but the above code i pasted still brings empty grid and pie chart
i have been tryin this for days now pls help me where am going wrong
Search my blog for XMLListCollection for an example.
can you tell me how do i extract int nodes
trace ( mychart.getDataLastResutlt.getDataResult.int[0] ) for example.
Then run your app in debug mode and see if any value is pulled out of the xml and displayed in the console.
trace (mychart.getDataLastResutlt.getDataResult.child("int") );
You can use the child() method to get the all the child nodes named "int"
Also if you want to send me the webservice you're using, I'll test it when I can.
http://livedocs.adobe.com/flex/201/html/13_Working...
The method is my webservice returns countries results in xml format and country name is CDATA type.
I am able to load countries xml data in TextArea control but not in the DataGrid control.
Does CDATA type has to do anything with datagrid not showing data ? I tried displaying just country id but that didn't solve the problem. Any help is appreciated .
I solved the issue. The issue is with resultFormat="e4x" attribute in the operaton tag. Once i removed it, the datagrid gets loaded but not the TextArea. I am trying to solve this, so it will display in TextArea and Datagrid just like in your example.
your tutorial is really helpful.But i want to know how to send an xmlstring from flex application to a webservice which accepts it as input parameter and do some processing.
thanx. waiting for ur reply
i used tmeout varible to close web service with in 2 min. but it does not release channels. total browser struked for ever.
i am unable to do new request unless i close and reopen the browser.
I am having problem when I use the .swf file in my .aspx file. When I am use your example (webServiceExample.html's .swf file in .aspx file and refer in <InvalidTag> tag, it works fine. But with my .swf file, it loads .swf file and once user make selections and click "OK" button, it just hangs up, and i don't get any error message. I am guessing there is a security issue. Any help is appreciated.
Thanks,
Siri
Siri
<?xml version="1.0" encoding="utf-8" ?>
<!DOCTYPE cross-domain-policy SYSTEM
"http://www.adobe.com/xml/dtds/cross-domain-policy....;
<cross-domain-policy>
<allow-access-from domain="domainName" />
</cross-domain-policy>
domainName have to be replaced with real domain name (for example: www.test.com, OR *.test.com, OR *), although it is not a good idea to replace with just '*'.
Thanks,
Siri
I've got an HTTPRequest object that's hitting the a dynamic page on the server that generates xml on the fly, by doing another server request that can't be helped. I find that it takes too long to return the xml, and Flex tries to parse the incomplete file, thus resulting in massive errors.
Is there a way to tell it to "wait 5 seconds" before parsing or accessing the file?
I want to clear about the data transmission that weather it needs any serialization or any configuration for simple webservice using wsdl.
Let me know the code of webservice(.asmx file). I'm getting concept and wokring on that, but blindly. So plz explain that whats going on behind.
Thanks,
Pradeep
Thank you for the good examples. I am trying to use the WebServiceX - stockquote service to pull in Stock data:
http://www.webservicex.net/stockquote.asmx?wsdl
I cannot seem to populate a single text field or label with individual node results from the returned Stock XML. Would you please explain the code needed to be able to parse the results for a single returned item. The following is an example of the returned results from this webservice.
<StockQuotes>
<Stock>
<Symbol>POZN</Symbol>
<Last>9.94</Last>
<Date>11/2/2007</Date>
<Time>3:00pm</Time>
<Change>-0.17</Change>
<Open>10.11</Open>
<High>10.11</High>
<Low>9.44</Low>
<Volume>674724</Volume>
<MktCap>295.2M</MktCap>
<PreviousClose>10.11</PreviousClose>
<PercentageChange>-1.68%</PercentageChange>
<AnnRange>8.29 - 19.75</AnnRange>
<Earns>-0.353</Earns>
<P-E>N/A</P-E>
<Name>POZEN INC</Name>
</Stock>
</StockQuotes>
I just want to be able to pull out individual children of the return and display them in a text field.
i.e. <mx.Label text="wsStock.GetQuote.lastResult.Symbol" or <mx.Label text="wsStock.GetQuote.lastResult.Last" - It just comes up blank when I try this.
How could one of your examples above be modified to accommodate this situation?
I appreciate any help you can offer with this.
Trace
1. See if the returned XML uses a name space and if so you must set a name space (see my discussion in other blog entries about name spaces)
2. Use { } around what you trying to bind the label's text value to
3. Try using toXMLString() (see my example)
IE
<mx.Label htmlText = "{xmlNode.here}" dataProvider=someHTTPRequest>
If you want to permanently save the changed XML, I've not done that. When I have data that must be changed in a Flex app and then stored after the changes were made I've used a database and ColdFusion on the backend.
Bruce
I tried your web service, it works perfectly. Thanks.
I created my own web service using Flex, the web service is served over a secure http(https). I put my flex app on a https server, however, I am not able to get access to the web service. Is it the problem of cross-domain policy as everyone said?
Here is the error I got when I run my flex app:
[RPC Fault faultString="Security error accessing url" faultCode="Channel.Security.Error" faultDetail="Unable to load WSDL. If currently online, please verify the URI and/or format of the WSDL (https://webserviceexample.asmx?WSDL)"]
Do you have a hint? Any suggestion will be greatly appreciated.
Thx
i am requesting a restircted webservice for the data and i using the resulted data to populate in my charts
the problem is my data is in the fromat
<NewDataSet>
<Categories>
<CategoryName>Accessories</CategoryName>
<Date>FY 2002</Date>
<SaleAmount xsi:type="xs:decimal" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">...;
</Categories>
</NewDataSet>
now i want to parse the above recieved XML file in the format of
<NewDataSet>
<Categories>
<CategoryName>Accessories</CategoryName>
<Date>2002</Date>
<SaleAmount xsi:type="xs:decimal" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">...;
</Categories>
</NewDataSet>
is it possible if so pls mail me the code
One doubt I have is in the WSDL document I am having, in the <soap binding> tag it does not have style attribute. But it does have it in the <operation> tag. Could this be the reason of the following error? Does flex try to see it in the <soap binding> tag?
Thanks in advance for your help.
[RPC Fault faultString="Unrecognized binding style 'null'. Only 'document' and 'rpc' styles are supported." faultCode="EncodingError" faultDetail="null"]
at mx.rpc.soap::Operation/http://www.adobe.com/2006/flex/mx/internal::invoke...()[E:\dev\3.0.x\frameworks\projects\rpc\src\mx\rpc\soap\Operation.as:774]
at mx.rpc.soap::Operation/send()[E:\dev\3.0.x\frameworks\projects\rpc\src\mx\rpc\soap\Operation.as:688]
at Function/http://adobe.com/AS3/2006/builtin::apply()
at mx.rpc.soap.mxml::Operation/send()[E:\dev\3.0.x\frameworks\projects\rpc\src\mx\rpc\soap\mxml\Operation.as:167]
at Function/http://adobe.com/AS3/2006/builtin::apply()
at mx.rpc::AbstractService/http://www.adobe.com/2006/actionscript/flash/proxy...()[E:\dev\3.0.x\frameworks\projects\rpc\src\mx\rpc\AbstractService.as:285]
I just tried your above example on web service, and it gave me error as below:
"fault: [FaultEvent fault=[RPC Fault faultString="Security error accessing url"
faultCode="Channel.Security.Error" faultDetail="Destination: DefaultHTTP"]"
Is this error related to the new release of Flash Player 9,0,124?
thanks!
Mel
I ran the example application in my browser with flash player version of 9.0.11.5.0 and it ran fine. After upgrading to 9.0.124 I get the same error as you. I know there were some additional security constraints added to calling web services that are in another domain in the latest flash player update so I'll have to research those.
This is one of the best and simplest example I could found on net. Thanks for this.
Now I know how to get xml data into Flex UI. I have another requirement wherein I need to submit the data from flex UI in XML format to the server side. How can I do that? Is that I have to write code to construct a xml string, taking values from my form fields or is there any other way ? I have not found any reference on this on net. Could you please help me and let me know the possible solutions. Thanks in advance
<mx:TextInput id="requestStatus_input" text="Enter text"/>
<mx:WebService id="requestStatus_ws" wsdl="http://...ip...:2580/process/GeneralStatusProcessW...;
fault="requestStatus_fault(event);" showBusyCursor="false">
<mx:operation name="GeneralStatusProcessWS" resultFormat="e4x" result="requestStatus_complete(event);">
<mx:request format="xml" xmlns:xs="http//www.w3.org/2001/XMLSchema">
<rootSys>
<systemId>{requestStatus_input.text}</systemId>
</rootSys>
</mx:request>
</mx:operation>
</mx:WebService>
Since I can't get the above to work, I tried it in ActionScript, but don't know how to set the (mx:)request part that contains the operator text input.
statusWebService = new WebService();
statusWebService.wsdl = settings.status.@wsdl; // getfrom file
statusWebService.addEventListener("load", requestStatus_load);
statusWebService.GeneralStatusProcessWS.resultFormat = "e4x";
statusWebService.GeneralStatusProcessWS.addEventListener("fault", requestStatus_fault);
statusWebService.GeneralStatusProcessWS.addEventListener("result", requestStatus_complete);
statusWebService.GeneralStatusProcessWS.request.format = "xml";
var requestXML:XML = <rootSys><systemId>{requestStatus_name_in}</systemId></rootSys>
statusWebService.GeneralStatusProcessWS.request = requestXML;
I've search many pages but can't find what I am after. Basically I have 2 questions. 1) What do I need to do to get the mxml working with dynamic operator input? 2) How can I pass dynamic operator input to the request in AS?
thanks in advance. Paul
I have no idea about programming and I have been fighting with Flex+WebServices for a month now; I read the livedocs, tons of blogs, followed so many tutorials, downloaded different software...and could not manage to call a service until I followed your simple instructions & code. If only I had found them earlier!!
Yet, I have a question. Your coding works fine with the service USZip. However, I have tried to develop simmilar codiing for other services hosted in the same webpage, such as http://www.webservicex.net/WCF/ServiceDetails.aspx... or http://www.webservicex.net/WCF/ServiceDetails.aspx... with no succes.
If I test the operations with the HTTP Post protocol available in webservicex.net for these services, I get a slightly different result to the one we got from USZIp.
What I mean is, in USZIP the XML which results from the query starts/ends with <NewDataSet><Table>...</Table></NewDataSet>.
On the other side, in Country Details, the structure is <string><NewDataSet><Table>...</Table></NewDataSet></String>.
I suspect that the structural differemt might be the source of my inhability to handle Country Details Service (and others).
Could you advice me on this?
Nice Example
When I run the same example from Flex3 it gives me Security Error in response of the GetCityInfo Method Call
In Flex2 it works.
Please Reply
Thanx :)
Im using flex and calling a .net webservice to fill a data grid clickin on a button but i get an error, hope you can help me! Here is my flex code, webservice is working in asp normally and returns an array of objects!
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" width="100%" height="100%">
<mx:WebService id="TestApp" wsdl="http://localhost:1574/Service%20References/Northwi...;
<mx:operation name="GetCategories">
</mx:operation>
</mx:WebService>
<mx:Button click="TestApp.GetCategories.send()" x="228" y="74"></mx:Button>
<mx:Binding source="{TestApp.GetCategories.result}" destination="dgData"/>
<mx:DataGrid id="dgData" dataProvider="{TestApp.GetCategories.result}" x="139" y="128">
<mx:columns>
<mx:DataGridColumn dataField="CustomerId" headerText="Customer ID"/>
<mx:DataGridColumn dataField="OrderId" headerText="Order ID"/>
</mx:columns>
</mx:DataGrid>
</mx:Application>
[RPC Fault faultString="Unrecognized binding style 'null'. Only 'document' and 'rpc' styles are supported." faultCode="EncodingError" faultDetail="null"]
at mx.rpc.soap::Operation/http://www.adobe.com/2006/flex/mx/internal::invoke...()[E:\dev\3.0.x\frameworks\projects\rpc\src\mx\rpc\soap\Operation.as:774]
at mx.rpc.soap::Operation/send()[E:\dev\3.0.x\frameworks\projects\rpc\src\mx\rpc\soap\Operation.as:688]
at Function/http://adobe.com/AS3/2006/builtin::apply()
at mx.rpc.soap.mxml::Operation/send()
I forgot to say that error happens with WCF webservice. I tested with ASMX using the internet samples and all ran well!
As i cant find WCF samples for Flex could you tell me if Flex doesnt support WCF or something like that? Thanks!
I ran your sample application there and I see that lovely security issue... I'm having the very same issue with my Flex application. It seems to work fine with older versions of the flash player 9, but if you use the latest version I get it.. I've updated my crossdomain.xml to the latest standards and I can run the application from my local machine.. When I go to upload it to my host server and run the application I get the error. If I use a computer which has a older version of the flash player it runs fine...
I'm guessing there's something I have to do on the client side here... I see from one of your last posts you were looking into this problem.. Any updates?
i have created a webservice which returns array of strings . i a calling the webservice through flex with resultformat e4x. returned value is
<HelloWorldResponse xmlns="http://tempuri.org/" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<HelloWorldResult>
<anyType xsi:type="xsd:string">kedar</anyType>
<anyType xsi:type="xsd:string">kedar</anyType>
<anyType xsi:type="xsd:string">kedar</anyType>
<anyType xsi:type="xsd:string">kedar</anyType>
<anyType xsi:type="xsd:string">kedar</anyType>
</HelloWorldResult>
</HelloWorldResponse>
now how can i access the individual string elements .i tried eventobject.result.lastResult.Property but its not working .plz help me out
but im getting error : Required parameter 'intNric' not found in input arguments
can you please let me find if there is any issue in this below code. thanks
regards
ganesh
<?xml version="1.0" encoding="utf-8"?>
<mx:Application pageTitle="Web Service Testing" xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute">
<mx:WebService id="TestApp" wsdl="http://localhost:2067/IPosRepositoryWebservice/Ser...; showBusyCursor="true">
<mx:operation name="GetPersonalDetails">
<mx:request>
<nric>12</nric>
</mx:request>
</mx:operation>
</mx:WebService>
<mx:Button label=" Click Here" click="TestApp.GetPersonalDetails.send()" x="228" y="74"></mx:Button>
<mx:Binding source="{TestApp.GetPersonalDetails.result}" destination="dgData"/>
<mx:DataGrid id="dgData" dataProvider="{TestApp.GetPersonalDetails.result}" x="139" y="128">
<mx:columns>
<mx:DataGridColumn dataField="nric" headerText="nric number"/>
<mx:DataGridColumn dataField="nationality" headerText="nationality"/>
</mx:columns>
</mx:DataGrid>
</mx:Application>
The following crossdomain.xml worked for me:
<cross-domain-policy>
<allow-access-from domain="*" secure="false"/>
<allow-access-from domain="*" to-ports="80,443"/>
<allow-http-request-headers-from domain="*" headers="*" />
</cross-domain-policy>
Whoever reads it may want to take a look at the original example:
http://wadearnold.com/blog//?p=20
crossdomain.xml must be in the root folder of the server hosting web services
I was able to access web services running a Flex client from a different domain and from a different physical server
Thanks for your code. Im getting value in xml formated but im not getting value in data grid. can you please help me to find the issue. thanks.
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute">
<mx:Script>
<![CDATA[
import mx.controls.Alert;
import mx.rpc.events.ResultEvent;
import mx.rpc.events.FaultEvent;
import mx.rpc.soap.LoadEvent;
import mx.collections.ArrayCollection;
import mx.managers.CursorManager;
import mx.utils.ArrayUtil;
private namespace webXNameSpace = "http://localhost:2067/IPosRepositoryWebservice&quo...;;
use namespace webXNameSpace;
]]>
</mx:Script>
<!--create the WebService component xml working -->
<mx:WebService
id="WS" wsdl="http://localhost:2067/IPosRepositoryWebservice/Ser...; useProxy="false"
fault="Alert.show(event.fault.faultString), 'Error'" showBusyCursor="true">
<!--specify the WebService method to use-->
<mx:operation name="GetPersonalDetails" resultFormat="e4x">
<!--specify the values for the method parameters-->
<mx:request>
<intNric>
{intNric.selectedItem.toString()}
</intNric>
</mx:request>
</mx:operation>
</mx:WebService>
<!--create user interface-->
<mx:Panel>
<mx:Spacer height="10"/>
<mx:Spacer height="15"/>
<mx:HBox>
<mx:Label text="Select Nric" width="101" fontSize="12"/>
<mx:ComboBox id="intNric" fontSize="12">
<mx:ArrayCollection>
<mx:String>10</mx:String>
<mx:String>12</mx:String>
<mx:String>15</mx:String>
</mx:ArrayCollection>
</mx:ComboBox>
</mx:HBox>
<mx:Spacer height="25"/>
<mx:HBox fontSize="12">
<mx:Button label="Get nric" click="WS.GetPersonalDetails.send()"/>
<mx:Label text="First nric Code: " fontSize="12">
</mx:Label>
<!--Bind the Text to the first Table element's nric node in the XML returned by the WebService-->
<mx:Text text="{WS.GetPersonalDetails.lastResult.GetPersonalDetailsResult.NewDataSet.Table1.nric}" width="253" fontSize="12"/>
</mx:HBox>
<mx:Spacer height="25"/>
<mx:Label text="Complete XML Returned: ">
</mx:Label>
<mx:HDividedBox width="800">
<!--bind the TextArea to the XML returned by the WebService-->
<mx:TextArea id="myTextArea" text="{WS.GetPersonalDetails.lastResult.toXMLString()}" width="390" height="400" fontSize="12"/>
<!--using the XML returned by the WebService populate the datagrid.
Table element has the data for each nric -->
<mx:DataGrid dataProvider="{WS.GetPersonalDetails.lastResult.GetPersonalDetailsResult.NewDataSet.Table1[0].nric}" height="400" fontSize="12">
<mx:columns>
<mx:DataGridColumn dataField="nric" headerText="nric" width="50"/>
<mx:DataGridColumn dataField="nationality" headerText="nationality" width="50"/>
<mx:DataGridColumn dataField="others" headerText="Others" width="70"/>
</mx:columns>
</mx:DataGrid>
</mx:HDividedBox>
</mx:Panel>
</mx:Application>
regards
ganesh
im getting error in this code . your example.
code:
<mx:DataGrid dataProvider="{WS.GetPersonalDetails.lastResult.GetPersonalDetailsResult.NewDataSet.Table1[0].nric}" height="400" fontSize="12">
error:
Data binding will not be able to detect changes when using square bracket operator.
for array, please use arraycollection.getItemat()instead