Revision as of 08:49, 3 October 2012 by hamishwillee (Talk | contribs)

Archived:How to access WebServices using WebServiceConnector component

From Nokia Developer Wiki
Jump to: navigation, search
Article Metadata
Created: mfabiop (11 Jun 2008)
Last edited: hamishwillee (03 Oct 2012)

In this tutorial, we will show how to access a web service easily using the WebServiceConnector component.

First of all, you've to had a web service started. We'll use a public web service to get current weather and weather conditions for major cities around the world. More details about this WebService can be view in [1]

Now, let's code the client.

  • You've to create a instance of WebServiceConnector into the Stage. Give it a instance name and set the WSDLURL field in Parameters panel.
  • Set the following fields in the parameters panel of WebServiceConnector instance:
    • WSDLURL: The url of the WSDL file location (local or remote).
    • operation: The name of the operation to be called.
  • You also have to create a UIComponent to show the recovered data from the WebService. In our example, we,ll use four labels. Like showed in the Figure.

Weather example.PNG

In the first frame of the timeline you have to add the following code:

//Here is created a 'wslistener' object that will be a event listener of the
//WebServiceConnector object. The event name is 'result'
var wslistener:Object = new Object();
wslistener.result = function(evt:Object){
location_txt.text = "Processing...";
time_txt.text = "Processing...";
sky_txt.text = "Processing...";
temperature_txt.text = "Processing...";
var result_xml = new XML();
result_xml.ignoreWhite = true;
location_txt.text = result_xml.childNodes[0].childNodes[0].firstChild.nodeValue;
time_txt.text = result_xml.childNodes[0].childNodes[1].firstChild.nodeValue;
sky_txt.text = result_xml.childNodes[0].childNodes[4].firstChild.nodeValue;
temperature_txt.text= result_xml.childNodes[0].childNodes[5].firstChild.nodeValue;
//We've to add the 'wslistener' object as a listener to 'weather_ws' object.
//When the operaion is finished, the 'wslistener.result' method will be invoked.
//When the button is pressed, the Web Service must be invoked.
get_btn.onPress = function(){
//The 'params' attribute receives an Array in the same order of the schema
//defined in WebServiceConnector compoent.
//Window -> Component Inspector -> Schema
weather_ws.params = [city_txt.text,country_txt.text]
  • Start the emulator or put the swf in the mobile phone.

Remember to put the SWF file in the \Others\Trusted folder if you want to use Flash Lite 3.0.

Further reading

67 page views in the last 30 days.