Thanks a lot for your appreciation and feedback. Much demanded topic Webservice has been covered for you. I request all of you to join as a member it will take hardly 2 mins so that you don't miss anything. We can also view your good face so Please add your image in profile.
What is a Web Service?
A Web service is a service on the web which can be parsed by Flash Player. We can invoke SOAP based Web service deployed on server. A Web service’s goal is to provide raw data in XML format to any application that makes a request to it. A Web service sits on a server much like any server-side page, and when a request is made to it, the Web service will perform a desired task, and return data in the form of XML. When using Flex Web service component, Objects returned by a web service are automatically deserialized into Action Script objects. Similarly Action Script objects passed as arguments to a web service operation are serialized according the wsdl description. Each Web service written will have a WSDL (Web Services Description Language) file that will describe Web service to anyone who intends to use it. Web services can be written in several different languages Like .net , ColdFusion etc.
Why Use Web Services?
It relies on standard Internet protocols HTTP and SOAP which are present in every system. Web services transport their messages using HTTP, which means these messages are transmitted over port 80, an open port for web server firewalls (Firewalls do not block Text information). Web service messages are transmitted as SOAP-formatted messages. SOAP messages are in XML format, meaning they are simply text, and not binary data. Any application written in any language running on any platform can process XML. Web services improve the way information flows between applications by making its information and its business logic available to other applications through an application programming interface (API). An API is a programming mechanism that allows an application to expose its functionality and to any other software application. So, API greatly supports application-to-application communication.
Let's take an example of a Web service:
It is a dictionary web service written in net. You can also view it at path below http://services.aonaware.com/DictService/DictService.asmx.
See the screenshot below:
You can see all the Web methods listed and their description if it was declared. Select the Define method and you will be taken to a new screen (see screenshot below).
Here you can invoke (run) the method to see its results. Also, you can see all the information about the method including its return value, and if we had any parameters, they would be shown here as well. Choose the Invoke button (specify any word in a text field), and another browser window will pop up with XML data as shown below in a screen shot. This is the result of the Web service.
As you see the web methods can be tested without an application. It gives enough information to a developer for its implementation.
Finally look at the WSDL screen shot below and at http://services.aonaware.com/DictService/DictService.asmx?WSDL
This tells any user of the Web service everything they need to know to use it. It shows all the methods, their return values, and their parameters.
Implementing Web Services with Flash 8:
We have already checked webs service, let’s take it a step further and bring the data into Flash.
We will begin working with the Web service and XML object to bring the data in Flash.
I have used temperature converter web service for this example. http://www.w3schools.com/webservices/tempconvert.asmx?WSDL
It has 2 methods for temperature conversion.
CelsiusToFahrenheit
FahrenheitToCelsius
Let’s have a look how to incorporate in Flash 8 using inbuilt Web service class.
import mx.services.WebService;
var wsdlURI = "http://www.w3schools.com/webservices/tempconvert.asmx?WSDL";
// Creates a new web service object.
var tempConvert:WebService = new WebService(wsdlURI);
// Receives the WSDL document after loading.
tempConvert.onLoad = function(wsdlDocument) {
//trace(wsdlDocument+"****");
// Code to execute when the WSDL loading is complete and the
// object has been created.
};
tempConvert.onFault = function(fault) {
//trace("Fault"+fault);
};
cToF_btn.onRelease = function() {
var callback1 = tempConvert.CelsiusToFahrenheit(cToF_txt.text);
callback1.onResult = function(result) {
cToFresult_txt.text = result;
};
};
fToC_btn.onRelease = function() {
var callback1 = tempConvert.FahrenheitToCelsius(fToC_txt.text);
callback1.onResult = function(result) {
fToCresult_txt.text = result;
};
};
Find the process below to implement the same Web service in Flex.
<?xml version="1.0"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" borderStyle="solid">
<mx:Script>
<![CDATA[
import mx.rpc.events.ResultEvent;
private var btnName:String="";
private function wsdlMethodResult(event:ResultEvent):void
{
if(btnName=="btn1")
{
//trace(event.result);
cToFresult_txt.text=String(event.result);
}
else if(btnName=="btn2")
{
//trace(event.result);
FToCresult_txt.text=String(event.result);
}
}
]]>
</mx:Script>
<mx:VBox>
<mx:HBox width="100%">
<mx:Label text="CelsiusToFahrenheit"/>
<mx:TextInput id="cToF_txt"/>
<mx:Button label="Convert" click="btnName='btn1';srv.CelsiusToFahrenheit(cToF_txt.text)"/>
<mx:Text width="100" id="cToFresult_txt"/>
</mx:HBox>
<mx:HBox width="100%">
<mx:Label text="FahrenheitToCelsius"/>
<mx:TextInput id="FToC_txt"/>
<mx:Button label="Convert" click="btnName='btn2';srv.FahrenheitToCelsius(FToC_txt.text)"/>
<mx:Text id="FToCresult_txt" width="100"/>
</mx:HBox>
</mx:VBox>
<mx:WebService id="srv" wsdl="http://www.w3schools.com/webservices/tempconvert.asmx?WSDL" result="wsdlMethodResult(event)" showBusyCursor="true"/>
</mx:Application>
See the screen shot below of the above programme.
Regards,
Faiz


This post have every thing that a novice can understand and emplement webservice in Flash..
ReplyDeletegreat effort..
Hello Faiz sir, How are you... can't we use webservice directly in flash using AS3 like we can do with AS2 in flash 8?
ReplyDeleteGreat to know that you became Krish from Krishna.:)
ReplyDeleteNow there is no inbuilt class in AS3 for a Webservice.:(
You can check Adulacent utility at
http://alducente.wordpress.com/2007/10/27/web-service-in-as3-release-10/
Keep in touch. Where are you working?