Connecting to a Web Service in Flex
I figured it was time to dive into Flex and see how different it is than Flash. There are some differences but not too many. For my first Flex project I decided to make an app to look up stock quotes. I figured this would be a good place to start because communicating with web services is a common task for ActionScript projects.
In this example I used WebserviceX.NET Stock Quote free web service. To connect to the webservice you have to instantiate a Web Service instance in your MXML file. Below is example syntax to instantiate a WebService in your MXML.
id : name to identify your web service
wsdl : web service address
fault : function to handle faults when connecting to your web service
result : function that will be called after connecting to your web service
Now it is time to make the call to your web service. The following code gets executed after the user clicks the search button. This code lives inside the same MXML page inside an <mx:Script> tag.
We are almost done. All we need to do now is display the results. This code also lives inside the same MXML page inside an <mx:Script> tag.
Take a look at the demo below. Currently we are getting a security issue because this demo is trying to access data from another domain. The solution is to add a crossdomain.xml in the root directory of the server but I do not have access to the blog's server root directory. Please download the source MXML file and add it to your Flex project to see it running.
Source MXML File
In this example I used WebserviceX.NET Stock Quote free web service. To connect to the webservice you have to instantiate a Web Service instance in your MXML file. Below is example syntax to instantiate a WebService in your MXML.
id : name to identify your web service
wsdl : web service address
fault : function to handle faults when connecting to your web service
result : function that will be called after connecting to your web service
Now it is time to make the call to your web service. The following code gets executed after the user clicks the search button. This code lives inside the same MXML page inside an <mx:Script> tag.
We are almost done. All we need to do now is display the results. This code also lives inside the same MXML page inside an <mx:Script> tag.
Take a look at the demo below. Currently we are getting a security issue because this demo is trying to access data from another domain. The solution is to add a crossdomain.xml in the root directory of the server but I do not have access to the blog's server root directory. Please download the source MXML file and add it to your Flex project to see it running.
Source MXML File







Interesting,
Keep up the good work,
Thanks for bringing this up
Reply to this