Handling Webservice using Flex
In this tutorial we are going to handle Webservice file from Flex. Before going deep into this
tutorial, Let us see what is a Webservice first.
Webservice:
The term Web services describes a standardized way of integrating Web-based applications using the
XML, SOAP, WSDL and UDDI open standards over an Internet protocol backbone. XML is used to tag the
data, SOAP is used to transfer the data, WSDL is used for describing the services available and
UDDI is used for listing what services are available. Used primarily as a means for businesses to
communicate with each other and with clients, Web services allow organizations to communicate data
without intimate knowledge of each other’s IT systems behind the firewall.
The basic Web services platform is XML + HTTP.
XML provides a language which can be used between different platforms and programming languages and
still express complex messages and functions.
The HTTP protocol is the most used Internet protocol.
Unlike Flash Flex has built in Webservice Component
<mx:WebService>
In webService we will be defining its ID and wsdl, wsdl points to the
http://www.webservicex.net/ValidateEmail.asmx?WSDL external location.
<mx:Operation>
Operation defines the webservice operation, here we will also mention result and fault event.
<mx:request>
request to send parameters to the webservice, if we are invoking an operation that does not need
parameter then no need to use tag.
once the webservice component is finished we will be invoking the webservice operation by
email.IsValidEmail.send();
Here email is webservice id, IsValidEmail is operation.
FullCode
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute">
<mx:Script>
<![CDATA[
import mx.rpc.events.FaultEvent;
import mx.controls.Alert;
import mx.rpc.events.ResultEvent;
private function onValidate(event:ResultEvent) : void
{
mx.controls.Alert.show(String(event.result));
}
private function onError(event:FaultEvent) : void
{
mx.controls.Alert.show(String(event.fault.faultDetail));
}
]]>
</mx:Script>
<mx:VBox>
<mx:TextInput id="text1"/>
<mx:Button id="ValidateEmail" label="ValidateEmail"
click="email.IsValidEmail.send();"/>
</mx:VBox>
<mx:WebService id="email" wsdl="http://www.webservicex.net/ValidateEmail.asmx?WSDL" showBusyCursor="true">
<mx:operation name="IsValidEmail" result="onValidate(event);"
fault="onError(event);">
<mx:request>
<Email>{text1.text}</Email>
</mx:request>
</mx:operation>
</mx:WebService>
</mx:Application>












































Leave your response!