<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Flex Tutorial &#187; Flex and Web Services</title>
	<atom:link href="http://flextutorial.org/category/flex-and-web-services/feed/" rel="self" type="application/rss+xml" />
	<link>http://flextutorial.org</link>
	<description>Rich Internet Application Development by Adobe Flex</description>
	<lastBuildDate>Fri, 11 Dec 2009 05:54:40 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.4</generator>
		<item>
		<title>Creating a Web Service Powered Flex Application in One Minute</title>
		<link>http://flextutorial.org/2009/03/04/creating-a-web-service-powered-flex-application-in-one-minute/</link>
		<comments>http://flextutorial.org/2009/03/04/creating-a-web-service-powered-flex-application-in-one-minute/#comments</comments>
		<pubDate>Wed, 04 Mar 2009 19:56:08 +0000</pubDate>
		<dc:creator>Bryan</dc:creator>
				<category><![CDATA[Flex and Web Services]]></category>
		<category><![CDATA[Consume Web Services]]></category>
		<category><![CDATA[Flex WebService]]></category>

		<guid isPermaLink="false">http://flextutorial.org/?p=163</guid>
		<description><![CDATA[This post belongs to the ‘How to Consume Web Services in Adobe Flex‘ series which provides tutorials and tips for Flex developers who want to access server-side data though Flex WebService. Read the introduction page here. Your Key to the World of Web Services &#8211; Flex WebService In old days, it sounded like very complex [...]]]></description>
			<content:encoded><![CDATA[<p><em>This post belongs to the ‘<a href="http://flextutorial.org/2009/03/03/how-to-consume-web-services-in-adobe-flex/">How to Consume Web Services in Adobe Flex</a>‘ series which provides tutorials and tips for Flex developers who want to access server-side data though Flex WebService. <a href="http://flextutorial.org/2009/03/03/how-to-consume-web-services-in-adobe-flex/">Read the introduction page here</a>.</em></p>
<p><strong><span style="color: #ff6600;">Your Key to the World of Web Services &#8211; </span></strong><strong><span style="color: #ff6600;">Flex WebService</span></strong></p>
<p><strong><span style="color: #ff6600;"><span id="more-163"></span></span></strong></p>
<p>In old days, it sounded like very complex to call web services. <em>SOAP, WSDL, Binding Style, Service, Port, Operation, Message, Type</em>&#8230; just name a few of technical jargons here, you might feel lost already.</p>
<p>However, it&#8217;s actually very easy  to consume web services in Adobe Flex because it provides a built-in component &#8211; <strong>WebService</strong>. By using it, you can literally <strong>Create a Web Service Powered Flex Application in One Minute</strong>. Is that amazing?</p>
<p><strong><span style="color: #ff6600;">Your First Flex WebService Application</span></strong></p>
<p>What we want to build here is a very simple Flex application, which converts a temperature value from Fahrenheit to Celsius. Behind the scene, it calls an online web service provided by <a href="http://www.w3schools.com/webservices/tempconvert.asmx">w3schools.com</a> to do the conversion.</p>
<p>The final Flex application will look like this:</p>
<p><img class="size-full wp-image-199 alignnone" title="flextutorial-003" src="http://flextutorial.org/wp-content/uploads/2009/03/flextutorial-003.jpg" alt="flextutorial-first-flex-webserivce-application-1" width="398" height="151" /></p>
<p>Once you type a Fahrenheit value (e.g. 100) into the input box and click <strong>Convert </strong>button, it will show the corresponding Celsius value.</p>
<p><img class="alignnone size-full wp-image-205" title="flextutorial-004" src="http://flextutorial.org/wp-content/uploads/2009/03/flextutorial-004.jpg" alt="flextutorial-first-flex-webserivce-application-2" width="398" height="151" /></p>
<p>Now, Let me show you how to build this Flex WebService application in <strong>4 simple steps</strong>. You can literally finish it within one minute.</p>
<p><strong><span style="color: #ff6600;">Step 1 &#8211; Create a New Project in Flex Builder</span></strong></p>
<ol>
<li><span style="color: #ff6600;"><span style="color: #000000;">Start your Flex Builder. On the top menu, click <strong>File -&gt; New -&gt; Flex Project</strong></span></span></li>
<li><span style="color: #ff6600;"><span style="color: #000000;">Give a name to your project, e.g. <em><strong>FlexWebService</strong></em>.</span></span><strong><span style="color: #ff6600;"> </span></strong></li>
<li><span style="color: #ff6600;"><span style="color: #000000;">Keep the default value for the rest parts, click <strong>Finish </strong>button.</span><br />
</span></li>
</ol>
<p style="padding-left: 30px;"><strong><img class="size-full wp-image-190 alignnone" title="flextutorial-001" src="http://flextutorial.org/wp-content/uploads/2009/03/flextutorial-001.jpg" alt="flextutorial-new-flex-webservice-project" width="557" height="589" /></strong></p>
<p><strong><span style="color: #ff6600;">Step 2 &#8211; Add Flex WebService Component</span></strong></p>
<p><span style="color: #ff6600;"><span style="color: #000000;">Flex provides a MXML tag <strong>&lt;mx:WebService&gt;</strong> to call web services, that is all you need right now. So just add the following lines to you main MXML file.</span></span><strong><span style="color: #ff6600;"><br />
</span></strong></p>
<blockquote>
<pre><span style="color: #0000ff;">&lt;mx:WebService</span> id="<span style="color: #ff0000;">myWebService</span>"
    wsdl="<span style="color: #ff0000;">http://www.w3schools.com/webservices/tempconvert.asmx?WSDL</span>"&gt;
    <span style="color: #0000ff;">&lt;mx:operation</span> name="<span style="color: #ff0000;">FahrenheitToCelsius</span>"
        result="<span style="color: #ff0000;">resultHandler(event)</span>"
        fault="<span style="color: #ff0000;">faultHandler(event)</span>"<span style="color: #0000ff;">&gt;</span>
    <span style="color: #0000ff;">&lt;/mx:operation&gt;</span>
<span style="color: #0000ff;">&lt;/mx:WebService&gt;</span></pre>
</blockquote>
<p>What have we just done?</p>
<ul>
<li>We create a &lt;mx:WebService&gt; with id <span style="color: #ff0000;">myWebService</span><em>.</em></li>
<li>We point &lt;mx:WebService&gt; to the URL (<span style="color: #ff0000;">http://www.w3schools.com/webservices/tempconvert.asmx?WSDL) </span>of a wsdl file created by our web service provider.</li>
<li>We specify the operation to use (<span style="color: #ff0000;">FahrenheitToCelsius</span>) and the functions to handle the result and fault event (<span style="color: #ff0000;">resultHandler </span>and <span style="color: #ff0000;">faultHandler</span>).</li>
</ul>
<p><strong><span style="color: #ff6600;">Step 3 &#8211; Add Flex WebService Event Handlers<br />
</span></strong></p>
<p>Now, we add the following code to handle the Flex WebService result and fault event.</p>
<blockquote>
<pre><span style="color: #000000;"><span style="color: #339966;">&lt;mx:Script&gt;</span>
    &lt;![CDATA[
	<span style="color: #0000ff;">import</span> mx.rpc.events.FaultEvent;
	<span style="color: #0000ff;">import </span>mx.rpc.events.ResultEvent;
	<span style="color: #0000ff;">import </span>mx.controls.Alert;

	<span style="color: #0000ff;">private </span><span style="color: #339966;">function </span>resultHandler(event:ResultEvent):<span style="color: #0000ff;">void </span>{
		<span style="color: #ff0000;">cValue.text = event.result.toString();</span>
	}

	<span style="color: #0000ff;">private </span><span style="color: #339966;">function </span>faultHandler(event:FaultEvent):<span style="color: #0000ff;">void </span>{
		<span style="color: #ff0000;">Alert.show(event.fault.message, "Error");</span>
	}
    ]]&gt;
<span style="color: #339966;">&lt;/mx:Script&gt;</span></span></pre>
</blockquote>
<p>The above code should be very simple to follow:</p>
<ul>
<li><strong>resultHandler </strong>function gets the web service&#8217;s return data from ResultEvent (event.result), converts it to a string, then bind it to a Flex Text component (cValue) for display.</li>
<li><strong>faultHandler </strong>function gets the fault error message from FaultEvent (event.fault.message) and use Alert window to display it.</li>
</ul>
<p><strong><span style="color: #ff6600;">Step 4 &#8211; Add Flex UI Components to Display the Temperature Converter<br />
</span></strong></p>
<p>In this last step, let&#8217;s create a simple UI:</p>
<blockquote>
<pre><span style="color: #000000;"><span style="color: #000000;"><span style="color: #0000ff;">&lt;mx:Panel</span> title="Fahrenheit to Celsis Converter"
    paddingTop="30" paddingRight="10"
    paddingBottom="30" paddingLeft="10"<span style="color: #0000ff;">&gt;</span>

    <span style="color: #0000ff;">&lt;mx:HBox&gt;</span>
	<span style="color: #0000ff;">&lt;mx:Label</span> text="Fahrenheit Value: "<span style="color: #0000ff;">/&gt;</span>
	<span style="color: #0000ff;">&lt;mx:TextInput</span> id="fValue" <span style="color: #0000ff;">/&gt;</span>
	<span style="color: #0000ff;">&lt;mx:Button</span> id="submit" label="Convert"
           click="<span style="color: #ff0000;">myWebService.FahrenheitToCelsius.send(fValue.text)</span>"<span style="color: #0000ff;">/&gt;</span>
    <span style="color: #0000ff;">&lt;/mx:HBox&gt;</span>

    <span style="color: #0000ff;">&lt;mx:HBox&gt;</span>
	<span style="color: #0000ff;">&lt;mx:Label</span> text="Celsius Value: "<span style="color: #0000ff;">/&gt;</span>
	<span style="color: #0000ff;">&lt;mx:Label</span> id="cValue"<span style="color: #0000ff;">/&gt;</span>
    <span style="color: #0000ff;">&lt;/mx:HBox&gt;</span>

<span style="color: #0000ff;">&lt;/mx:Panel&gt;</span></span></span></pre>
</blockquote>
<p>Basically, we create a Panel which contains two HBox to get user input and display the result from the web service. The only thing special here is the <strong>Click Event</strong> of the Submit button.</p>
<blockquote>
<pre><span style="color: #000000;"><span style="color: #000000;"><span style="color: #0000ff;">&lt;mx:Button</span> id="submit" label="Convert"
    click="<span style="color: #ff0000;">myWebService.FahrenheitToCelsius.send(fValue.text)</span>"<span style="color: #0000ff;">/&gt;</span>
</span></span></pre>
</blockquote>
<p>Here we refer to our Flex WebService through its id <span style="color: #ff0000;">myWebService</span>, call its operation <span style="color: #ff0000;">FahrenheitToCelsius<span style="color: #000000;">,</span> </span>and pass a value coming from the TextInput control <span style="color: #ff0000;">fValue</span>.</p>
<p>Now let&#8217;s click Run button in your Flex builder and see what will happen&#8230; &#8230;</p>
<blockquote><p><strong><span style="color: #000000;">Congratulations! You Have Created a Web Service Powered Flex Application!</span></strong></p></blockquote>
<p><span style="color: #ff6600;"><span style="color: #ff6600;"><strong>Recap what you have learned so far</strong></span></span></p>
<ul>
<li><span style="color: #ff6600;"><span style="color: #000000;">You can consume web services in Flex simply through <strong>&lt;mx:WebService&gt;</strong>.</span></span></li>
<li><span style="color: #ff6600;"><span style="color: #000000;">You can specify <em>wsdl url, operation name, result event handler, fault event handler</em> for <strong>&lt;mx:WebService&gt;</strong>.</span></span></li>
<li><span style="color: #ff6600;"><span style="color: #000000;">You can trigger your WebService through an event (like button click event), call the send function of the operation, and pass parameters if needed.</span></span></li>
</ul>
<p>Through the sample application we built today, I hope you will see how easy it is to consume web services in Flex.  You can <a href="http://flextutorial.org/wp-content/uploads/2009/03/FlexWebService.mxml">download the complete source code here</a>.</p>
<p>If you have any questions, please feel free to comment on this post or <a href="http://flextutorial.org/contact/">contact me directly</a> .</p>
<p>For the next tutorial, we will talk about some details in Flex WebService and help you thoroughly understand it from A to Z.</p>
]]></content:encoded>
			<wfw:commentRss>http://flextutorial.org/2009/03/04/creating-a-web-service-powered-flex-application-in-one-minute/feed/</wfw:commentRss>
		<slash:comments>18</slash:comments>
		</item>
		<item>
		<title>How to Consume Web Services in Adobe Flex</title>
		<link>http://flextutorial.org/2009/03/03/how-to-consume-web-services-in-adobe-flex/</link>
		<comments>http://flextutorial.org/2009/03/03/how-to-consume-web-services-in-adobe-flex/#comments</comments>
		<pubDate>Tue, 03 Mar 2009 18:06:06 +0000</pubDate>
		<dc:creator>Bryan</dc:creator>
				<category><![CDATA[Flex and Web Services]]></category>
		<category><![CDATA[Flex WebService]]></category>
		<category><![CDATA[X Consume Web Services]]></category>

		<guid isPermaLink="false">http://flextutorial.org/?p=104</guid>
		<description><![CDATA[Help! My Flex application is cool, but where are the data from? You spend quit a lot of time building your Flex application with nice layout, fancy panels, and cool animations. Then all of a sudden, you realize one thing is missing: Where and How to get the server-side data for my Flex application? It feels [...]]]></description>
			<content:encoded><![CDATA[<p><strong><span style="color: #000000;">Help! My Flex application is cool, but where are the data from?</span></strong></p>
<p>You spend quit a lot of time building your Flex application with nice layout, fancy panels, and cool animations. Then all of a sudden, you realize one thing is missing: <strong></strong></p>
<blockquote><p><strong>Where and How to get the server-side data for my Flex application?</strong></p></blockquote>
<p>It feels like <strong>you have just got a most powerful cannon, but no ammunition to fire</strong>.</p>
<p>Using Adobe Flex as a <strong>front-end </strong>RIA tool, many people are familiar with common Flex components like <em>Panel</em>, <em>HBox</em>, or <em>TileList</em>. However, when coming to the topic like <strong>How to Consume Web Services in Adobe Flex</strong>, you might encounter some challenges including:</p>
<p><span id="more-104"></span></p>
<blockquote>
<ul>
<li>What Flex component can I use to call web services?</li>
<li>What are the differences among Flex WebService, HttpService, and RemoteObject?</li>
<li>What is SOAP? What is WSDL? How to interpret a WSDL and map it to Flex WebService?</li>
<li>How to consume Web Services in both MXML and ActionScript?</li>
<li>How to pass request parameters to Web Services from Flex?</li>
<li>How to set up the return data format for Flex WebService?</li>
<li>How to handle the Flex WebService events, such as result event and fault event?</li>
<li>How to retrieve, sort, filter, and bind the Web Services data in Flex?</li>
<li>Is there any automatic tool to simplify my work on consuming Web Services in Flex?</li>
</ul>
</blockquote>
<p>Over the next week, I want to write a series of 5 tutorials for Flex users facing some of the above problems &#8211; those who need to<strong> access server-side data by consuming web services in Adobe Flex</strong> and who need ammunition for their RIA cannon.</p>
<p>Here are the topics we will be covering over the next week:</p>
<ol>
<li><a href="http://flextutorial.org/2009/03/04/creating-a-web-service-powered-flex-application-in-one-minute/">Creating a Web Service Powered Flex Application in One Minute</a></li>
<li>Understanding Flex Web Service from A to Z</li>
<li>Mapping SOAP and WSDL to Flex WebService</li>
<li>Retrieving, Processing, and Binding Web Services Data in Flex</li>
<li>Utilizing Tools to Simplify the Work on Consuming Web Services in Flex</li>
</ol>
<p>To follow along with this series, make sure you <a href="http://flextutorial.org/feed/">subscribe to our RSS feed</a> or bookmark and come back to this page.</p>
<p>Stay tuned for the next post of this tutorial series on <strong>How to Comsume Web Services in Adobe Flex</strong>.</p>
]]></content:encoded>
			<wfw:commentRss>http://flextutorial.org/2009/03/03/how-to-consume-web-services-in-adobe-flex/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
	</channel>
</rss>
