<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom" 
      xmlns:thr="http://purl.org/syndication/thread/1.0">
  <link rel="alternate" type="text/html" href="http://www.insideria.com/2009/04/flex-101-rpc-basics.html" />
  <link rel="self" type="application/atom+xml" href="http://www.insideria.com/atom.xml" />
  <id>tag:www.insideria.com,2009://34/tag:www.insideria.com,2009://34.36091-</id>
  <updated>2009-11-16T15:04:22Z</updated>
  <title>Comments for Flex 101: RPC Basics (http://www.insideria.com/2009/04/flex-101-rpc-basics.html)</title>
  <generator uri="http://www.sixapart.com/movabletype/">Movable Type 4.21-en</generator>
  <entry>
    <id>tag:www.insideria.com,2009://34.36091</id>
    <link rel="alternate" type="text/html" href="http://www.insideria.com/2009/04/flex-101-rpc-basics.html" />
    <link rel="service.edit" type="application/atom+xml" href="http://blogs.oreilly.com/cgi-bin/mt/mt-atom.cgi/weblog/blog_id=34/entry_id=36091" title="Flex 101: RPC Basics" />
    <published>2009-05-01T00:20:21Z</published>
    <updated>2009-05-01T01:33:53Z</updated>
    <title>Flex 101: RPC Basics</title>
    <summary>When building Flex applications, it is important to understand how to get data into and out of your applications and remote procedure calls (rpc).    In this post, I&apos;ll try to shed some light on HTTPService, WebService, and RemoteObject classes and their usage.</summary>
    <author>
      <name>Andrew Trice</name>
      
    </author>
    
    <category term="Blogs" />
    
    <content type="html" xml:lang="en" xml:base="http://www.insideria.com/">
      <![CDATA[When building Flex applications, it is important to understand how to get data into and out of your applications and remote procedure calls (rpc).    In this post, I'll try to shed some light on HTTPService, WebService, and RemoteObject classes and their usage.
<br/><br/>

By W3C definition, a "<a target="_blank" href="http://en.wikipedia.org/wiki/Web_service">web service</a>" is a software system designed to support interoperable machine-to-machine interaction over a network.  All three of these classes are used to support this concept.
<br/><br/>

<strong>HTTPService</strong><br/>

The HTTPService class is a rpc class that is used to load data from any url over http.  This is typically used to load text-based files (free-text, XML, CSV, etc...) that are served by a web server.   They can be static files, or dynamically created, and will work with any server-side technology.   You would use the HTTPService class to access <a target="_blank" href="http://en.wikipedia.org/wiki/Restful_web_service">restul web services</a> (not to be confused with the web services described below).<br/><br/>

<div class="acode" style="overflow: auto; padding: 10px;" ><div style="overflow-x: visible;"> 
<code language="perl">
<pre>
&lt;mx:HTTPService 
	id="<span class="quote">myHttpService</span>"
	<span class="category2">url</span>="<span class="quote">http://myurl/myfile.xml</span>"
	result="<span class="quote">resultHandler(event)</span>"
	fault="<span class="quote">faultHandler(event)</span>" /&gt;</pre>
</code>
 
</div></div> 

You can read more about the HTTPService class online at:<br/>
<a target="_blank" href="http://livedocs.adobe.com/flex/3/langref/mx/rpc/http/mxml/HTTPService.html">http://livedocs.adobe.com/flex/3/langref/mx/rpc/http/mxml/HTTPService.html</a><br/>
<a target="_blank" href="http://livedocs.adobe.com/flex/3/html/data_access_2.html#193905">http://livedocs.adobe.com/flex/3/html/data_access_2.html#193905</a>

<br/><br/>


<strong>WebService</strong><br/>
The WebService class is a class for accessing WSDL-based <a target="_blank" href="http://en.wikipedia.org/wiki/Web_service">web services</a> within your flex applications.   The <a target="_blank" href="http://livedocs.adobe.com/flex/3/html/help.html?content=data_access_3.html#193910">online Flex documentation</a> sums it up nicely:
<br/><br/>

<blockquote>Flex applications can interact with web services that define their interfaces in a Web Services Description Language 1.1 (WSDL 1.1) document, which is available as a URL. WSDL is a standard format for describing the messages that a web service understands, the format of its responses to those messages, the protocols that the web service supports, and where to send messages. The Flex web service API generally supports Simple Object Access Protocol (SOAP) 1.1, XML Schema 1.0 (versions 1999, 2000, and 2001), and WSDL 1.1 RPC-encoded, RPC-literal, and document-literal (bare and wrapped style parameters). The two most common types of web services use remote procedure call (RPC) encoded or document-literal SOAP bindings; the terms encoded and literal indicate the type of WSDL-to-SOAP mapping that a service uses. </blockquote>


<div class="acode" style="overflow: auto; padding: 10px;" ><div style="overflow-x: visible;"> 
<code language="perl">
<pre>
&lt;mx:WebService 
	id="<span class="quote">myWebService</span>"
	wsdl="<span class="quote">http://myserver/myservice.svc?wsdl'}</span>" /&gt;</pre>
</code>
 
</div></div> 



You can read more about the WebService class online at:<br/>
<a target="_blank" href="http://livedocs.adobe.com/flex/3/html/data_access_3.html#193910">http://livedocs.adobe.com/flex/3/html/data_access_3.html#193910</a><br/>
<a target="_blank" href="http://livedocs.adobe.com/flex/3/langref/mx/rpc/soap/mxml/WebService.html">http://livedocs.adobe.com/flex/3/langref/mx/rpc/soap/mxml/WebService.html</a>
<br/><br/>


<strong>RemoteObject</strong><br/>
The RemoteObject class is used to handle Flash Remoting rpc calls within Flex applications.   RemoteObject services calls are conceptually the same as web services, however data is transferred using the <a target="_blank" href="http://download.macromedia.com/pub/labs/amf/amf3_spec_121207.pdf">AMF</a> protocol, which is generally more compact and faster to parse than xml-based web services (especially with large data sets).   
<br/><br/>

<div class="acode" style="overflow: auto; padding: 10px;" ><div style="overflow-x: visible;"> 
<code language="perl">
<pre>
&lt;mx:RemoteObject 
	id="<span class="quote">myRemoteObject</span>" 
	destination="<span class="quote">myDestination</span>"/&gt;</pre>
</code>
 
</div></div> 


You can read more about the RemoteObject class online at:<br/>
<a target="_blank" href="http://livedocs.adobe.com/flex/3/html/data_access_4.html#202412">http://livedocs.adobe.com/flex/3/html/data_access_4.html#202412</a><br/>
<a target="_blank" href="http://livedocs.adobe.com/flex/3/langref/mx/rpc/remoting/mxml/RemoteObject.html">http://livedocs.adobe.com/flex/3/langref/mx/rpc/remoting/mxml/RemoteObject.html</a>
<br/><br/>


Security sandbox restrictions apply to all three of these classes, so be sure to understand security restrictions and <a href="http://www.adobe.com/devnet/flashplayer/articles/fplayer9_security.html" target="_blank">read up on cross-domain policies</a>.

<br/><br/>


___________________________________<br/>
<strong>Andrew Trice</strong><br/>
Principal Architect<br/>
<a href="http://www.cynergysystems.com" target="_blank">Cynergy Systems<br/>
http://www.cynergysystems.com</a>]]>
      
    </content>
  </entry>

  <entry>
    <id>tag:www.insideria.com,2009://34.36091-comment:2058748</id>
    <thr:in-reply-to ref="tag:www.insideria.com,2009://34.36091" type="text/html" href="http://www.insideria.com/2009/04/flex-101-rpc-basics.html"/>
    <link rel="alternate" type="text/html" href="http://www.insideria.com/2009/04/flex-101-rpc-basics.html#comment-2058748" />
    <title>Comment from Nick Wiggill on 2009-05-02</title>
    <author>
        <name>Nick Wiggill</name>
        <uri>http://www.visualharmonics.co.uk</uri>
    </author>
    <content type="html" xml:lang="en" xml:base="http://www.visualharmonics.co.uk">
        <![CDATA[<p>I think anything that clarifies why one would pick one option as opposed to another in Flex in useful. In particular comms; I struggled with this on my initial bouts with Flex, wondering if I had picked the right option for what I was trying to achieve.</p>

<p>As always, "sucks to livedocs"!</p>]]>
    </content>
    <published>2009-05-02T15:24:57Z</published>
  </entry>

  <entry>
    <id>tag:www.insideria.com,2009://34.36091-comment:2058902</id>
    <thr:in-reply-to ref="tag:www.insideria.com,2009://34.36091" type="text/html" href="http://www.insideria.com/2009/04/flex-101-rpc-basics.html"/>
    <link rel="alternate" type="text/html" href="http://www.insideria.com/2009/04/flex-101-rpc-basics.html#comment-2058902" />
    <title>Comment from Todd on 2009-05-05</title>
    <author>
        <name>Todd</name>
        <uri>http://www.simplifiedchaos.com</uri>
    </author>
    <content type="html" xml:lang="en" xml:base="http://www.simplifiedchaos.com">
        <![CDATA[<p>Usually existing backends/developer skills determine which method to go with.  However, if you're a sole-dev, working on a simple solution by yourself, I'd stick to using HTTPService and textual-based request/response, as it's the easiest to work with AND provides the most flexibility.</p>

<p>With WebService, you'll have to navigate the complex SOAP-based world and have to have your requests/responses form to predefined schemas, and your backend tools will need to output correct responses based on those schemas (not necessarily as easy as it should be).  And WebService implementations by different back-end tools and providers aren't nearly as interoperable as they'd like you to believe.</p>

<p>With RemoteObject, you'll need a serverside service that supports AMF.  Which, luckily, has been open-sourced and has an implementation in just about every server-side technology you can think of.  Things are a bit trickier to debug this on the wire, however, since it's binary data.  However, like Andrew mentioned, in a lot of cases the data is compact and transfers faster, and Flex even unmarshells it quickly in the Flash Player due to using some low-level, platform-optimized code.</p>

<p>Now, my favorite: HttpService.  Transfers data back and forth across the wire in plain text.  Easy to debug.  No tight data contract (could be a negative, though, depending on complexity of system).  You can encode data in XML, JSON, cusotm-text or whatever textual style you want -- using JSON might be necessary if you already have existing server-side code.</p>

<p>When I can, I start with HttpService, and then move to the others as needed.  For example, in some enterprise solutions, I've been required to use WebService and ...but even that's starting to lessen these days.</p>]]>
    </content>
    <published>2009-05-05T14:02:08Z</published>
  </entry>

  <entry>
    <id>tag:www.insideria.com,2009://34.36091-comment:2059261</id>
    <thr:in-reply-to ref="tag:www.insideria.com,2009://34.36091" type="text/html" href="http://www.insideria.com/2009/04/flex-101-rpc-basics.html"/>
    <link rel="alternate" type="text/html" href="http://www.insideria.com/2009/04/flex-101-rpc-basics.html#comment-2059261" />
    <title>Comment from Kshama on 2009-05-10</title>
    <author>
        <name>Kshama</name>
        <uri></uri>
    </author>
    <content type="html" xml:lang="en" xml:base="">
        <![CDATA[<p>Hi there,<br />
In my application, I have TileList with a image and label in each<br />
tile. The image and label is retrieved from a xml file.However, when I run the project it fails and points to default FaultHandler function. </p>

<p>On further debugging, I realized that length of XML data returned from HTTPService is 0. So the httpservice is unable to hit the xml file..right ?</p>

<p>here is the code:</p>

<p><br />
       <br />
     	 
     	 	import mx.collections.ArrayCollection;<br />
     	      import mx.collections.XMLListCollection;<br />
        	import mx.rpc.events.ResultEvent;<br />
     	 	[Bindable]<br />
     	 	private var itemlist :XMLList;<br />
     	 	private var itemlistcoll : XMLListCollection<br />
     	      private function xmlLoaded(evt:ResultEvent):void {<br />
     	            itemlist = evt.result.catalog;<br />
     	           trace( itemlist.length());<br />
     	         <br />
     	            }<br />
     	   ]]&gt;     <br />
     	<br />
     <br />
    </p>

<p><br />
Can you please throw some light on what must have gone wrong.</p>

<p>Also, if the  dataprovider for TileList is  srv.LastResult.catalog, it seems to load the label but not image ( image is replaced by a small cross ).</p>

<p>Thanks,<br />
Kshama</p>]]>
    </content>
    <published>2009-05-10T16:50:06Z</published>
  </entry>

  <entry>
    <id>tag:www.insideria.com,2009://34.36091-comment:2110772</id>
    <thr:in-reply-to ref="tag:www.insideria.com,2009://34.36091" type="text/html" href="http://www.insideria.com/2009/04/flex-101-rpc-basics.html"/>
    <link rel="alternate" type="text/html" href="http://www.insideria.com/2009/04/flex-101-rpc-basics.html#comment-2110772" />
    <title>Comment from Rodolph Stuart on 2009-09-22</title>
    <author>
        <name>Rodolph Stuart</name>
        <uri></uri>
    </author>
    <content type="html" xml:lang="en" xml:base="">
        <![CDATA[<p>In response to my own message, the problem was due me putting the parameters<br />
in the wrong order :P  The correct order should be;</p>

<p>Key<br />
Value<br />
TTL<br />
Application name</p>

<p>For a standard 'put', for a 'put_removable' it should be;</p>

<p>Key<br />
Value<br />
Secret algorithm<br />
Secret hash<br />
TTL<br />
Application name</p>

<p>This all became clear when I took the time to learn the basics of Python and<br />
understand what those scripts were doing.</p>

<p>I can now successfully 'put' (and 'put_removable') and 'get' with no<br />
problems!!  However :( I get an error when trying to do an 'rm'.  I'm fairly<br />
confident I'm calling the method right this time as I've essentially used<br />
the format of the Python script available.  The error I'm getting is this;</p>

<p>Avoiding obscuring previous error by supressing error encountered while<br />
ending request: org.apache.xmlrpc.XmlRpcClientException: Exception closing<br />
URLConnection</p>

<p>Thanks.</p>

<p>Rodolph Stuart<br />
<a href="http://www.etil.com.br">Lampadas</a></p>]]>
    </content>
    <published>2009-09-22T20:14:02Z</published>
  </entry>

</feed
