Accessibility

TechNote (Archived)

Example for accessing data from .net web services

In Macromedia Flex, you can access data from a web service that is created by a different language, such as .net, Java or ColdFusion. This TechNote provides an example of using a .net web service from http://www.webservicex.com/.

Preparation

To use an existing web service from the Internet in your Flex application, you must first verify that the web service and all its methods are working correctly.

Using the .net Translation Engine web service from http://www.webservicex.com/ as an example, check the following:

If you are using your own web service, verify it works on the machine where you have Flex deployed.

Implementation

Since the Flash Player is working in a security sandbox, you need to make configuration changes so that the Flex application can access the web service you are trying to use.

If you are using the proxy servlet provided by Flex, you need to add<url>http://www.webservicex.com/*</url> under the <unnamed> section of <whitelist> under<web-service-proxy> in the flex-config.xml file. See TechNote 19251 for more details.

Troubleshooting

The <mx:WebService ...></mx:WebService> tag can only be put under the root tag (<mx:Application..></Application>). If you put the WebService tag inside a container, such as<VBOX></VBox>, then you will get the following error displayed in the browser:

 Error /lin/transaltionEng.mxml:54  Faceless components may only be allowed as children of the root tag 53:    <!-- web service -->> 54:    <mx:WebService id="fish" wsdl="http://www.webservicex.com/TranslateService.asmx?WSDL"> 55:        <mx:operation name="Translate"> 
Example

Here is example code, using the Translation Engine from www.webservicex.com/, to convert text from one language to another:

 <?xml version="1.0" encoding="iso-8859-1"?><mx:Application width='700'  xmlns:mx="http://www.macromedia.com/2003/mxml" ><!-- This is a simple demo of a web service call with two-way binding --><mx:VBox   backgroundColor="35515157577070"><mx:Label text=" Translation Engine"   fontSize="24"/><mx:Form    backgroundColor="25589"><!-- page design --><mx:Label   fontSize="18" text="Translate a block of text (Enter up to 150 words)"/><mx:Label   fontSize="14" text="from http://www.webservicex.com/ .net web services"/><mx:TextInput id="input"    /><mx:HBox ><mx:ComboBox id="translation" initialize="initCB()" /><mx:Script>         function initCB() {            translation.dataProvider=[              {label:"English -> Chinese", data:"EnglishTOChinese"},              {label:"English -> Japanese", data:"EnglishTOJapanese"},              {label:"English -> French", data:"EnglishTOFrench"},              {label:"English -> German", data:"EnglishTOGerman"},              {label:"English -> Italian", data:"EnglishTOItalian"},              {label:"English -> Portugese", data:"EnglishTOPortuguese"},              {label:"English -> Spanish", data:"EnglishTOSpanish"},              {label:"French -> English", data:"FrenchTOEnglish"},              {label:"German -> English", data:"GermanTOEnglish"},              {label:"Italian -> English", data:"ItalianTOEnglish"},              {label:"Portugese -> English", data:"PortugueseTOEnglish"},              {label:"Russian -> English", data:"RussianTOEnglish"},              {label:"Spanish -> English", data:"SpanishTOEnglish"}];            trace(output.text);         }</mx:Script><mx:TextInput text="{translation.selectedItem.data}"  height='23' fontSize="12"/><mx:Button  label="Translate Now" click='fish.Translate.send()'/></mx:HBox><mx:TextArea id="output"  height='100' text="{fish.Translate.result}" fontSize="12"/></mx:Form></mx:VBox><!-- web service should be under root tag, can't be inside a container like VBox, Form, etc--><mx:WebService id="fish" wsdl="http://www.webservicex.com/TranslateService.asmx?WSDL"><mx:operation name="Translate"><mx:request><Text>{input.text}</Text><LanguageMode>{translation.value}</LanguageMode></mx:request></mx:operation></mx:WebService></mx:Application> 


AlertThis content requires Flash

To view this content, JavaScript must be enabled, and you need the latest version of the Adobe Flash Player.

Download the free Flash Player now!

Get Adobe Flash Player

Creative Commons License

Search Support


Document Details

ID:tn_19327
Browser:Chrome
Internet Explorer
Netscape
Opera
Safari
Firefox

Products Affected:

flex