My favorites | Sign in
Project Logo
                
Search
for
Updated Feb 25, 2007 by akeemphilbert
Labels: Phase-Implementation, Featured
Resources  
Tutorials, External Links, Code Samples

Documentation

Each RPC type is based on a AbstractRPCObject which mimics the native http://livedocs.macromedia.com/flex/2/langref/. Since the implementation is the same for the different RPC types (AMF0,XML-RPC and JSON-RPC), AbstractObject will be used to generalize them in the examples. Simply replace <ak33m:AbstractObject> with the appropriate tags:

RPC Type Package AS Class MXML Tag
AMF0 (Flash Remoting) com.ak33m.rpc.amf0.* AMF0Object <ak33m:AMF0Object>
XML-RPC com.ak33m.rpc.xmlrpc.* XMLRPCObject <ak33m:XMLRPCObject>
JSON-RPC com.ak33m.rpc.jsonrpc.* JSONRPCObject <ak33m:JSONRPCObject>

General Example:

<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" xmlns:ak33m="http://ak33m.com/mxml" creationComplete="callFunction();">
    <mx:Script>
       <![CDATA[
         import mx.controls.Alert;
         function callFunction ()
         {
           //sample method call using token pattern
           someapi.doSomeThing(param1,param2);
          //sample method call if method has a dot (.) (as is the case with blog xmlrpc API
          someapi.call("method.with.dot",param1,param2);
         }
      ]]>
   </mx:Script>
    <ak33m:AbstractObject id="someapi" endpoint="http://ak33m.com" destination="someendpoint" fault="Alert.show(event.fault.faultString,event.fault.faultCode)">
    </ak33m:AbstractObject>
</mx:Application>

Below is an example using the xmlrpc api of a blog. It uses the token pattern and the ItemResponder.

NB Any class that implements IResponder can be used. ItemResponder is the only responder natively available in Flex 2&copy; and hence utilized in this example

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" xmlns:ak33m="http://ak33m.com/mxml" creationComplete="">
	<mx:Script>
		<![CDATA[
			import mx.rpc.events.ResultEvent;
			import mx.rpc.events.FaultEvent;
			import mx.rpc.AsyncToken;
			import mx.controls.Alert;
			import mx.collections.ItemResponder;
			var urlregexp:String = "^[A-Za-z]+://[A-Za-z0-9-_]+\\.[A-Za-z0-9-_%&\?\/.=]+$";
			var endpointregexp:String = "/[A-Za-z0-9-_%&\?\/.=]";
			function login ()
			{
				//This is the rpc call. Because the xmlrpc service used in this example has functions with dots (.) in them the call function is used
				//if there was no dot the call could be blogapi.getUserInfo ()
				var token:AsyncToken = blogapi.call("blogger.getUserInfo","",user_txt.text,password_txt.text);
				var tresponder:ItemResponder = new ItemResponder(this.showUserInfo,this.onFault);
				
				token.addResponder(tresponder);
			}
			
			function showUserInfo (event:ResultEvent,token = null)
			{
				Alert.show("User: "+event.result.nickname,"User info result");
			}
			
			function onFault (event:FaultEvent, token=null)
			{
				Alert.show(event.fault.faultString,event.fault.faultCode);
			}
		]]>
	</mx:Script>
	<!-- Validation -->
	  <mx:RegExpValidator id="regExpV" 
        source="{rooturl_txt}" property="text" 
        flags="g" expression="{urlregexp}" noMatchError="Please enter a valid URL"
      />
     <mx:RegExpValidator id="endpointregExpV" 
        source="{this.endpoint_txt}" property="text" 
        flags="g" expression="{endpointregexp}" noMatchError="Please enter a valid endpoint. It MUST start with a /"
      />
     <!-- User Interface -->
	<mx:Panel height="300" width="380">
		<mx:Form height="200" width="350" x="0" y="0">
			<mx:FormHeading label="Blog Login" textAlign="left"/>
			<mx:FormItem label="Root URL">
				<mx:TextInput id="rooturl_txt"/>
			</mx:FormItem>
			<mx:FormItem label="Xmlrpc endpoint">
				<mx:TextInput id="endpoint_txt"/>
			</mx:FormItem>
			<mx:FormItem label="Username">
				<mx:TextInput id="user_txt"/>
			</mx:FormItem>
			<mx:FormItem label="Password">
				<mx:TextInput id="password_txt"/>
			</mx:FormItem>
			<mx:FormItem>
				<mx:Button label="Send" id="send_btn" click="login();"/>
			</mx:FormItem>
		</mx:Form>
	</mx:Panel>
	<!-- RPC Object -->
	<ak33m:XMLRPCObject id="blogapi" endpoint="{rooturl_txt.text}" destination="{endpoint_txt.text}" >
		
	</ak33m:XMLRPCObject>
</mx:Application>

External Links

Specifications


Comment by bensmeets, Sep 02, 2007

How to add this to a Cairngorm delegate :(

Comment by bensmeets, Sep 02, 2007

How to add this to a Cairngorm delegate :(

Comment by egoing, Sep 12, 2007

df

Comment by dorkiedorkfromdorktown, Oct 23, 2007

Can you post example code of calling a method of a service class using AMFPHP? Thank you!!!

Comment by tommyw13, Nov 05, 2007

I noticed that the final .swc file was 440K+. Is there anyway to make it smaller? I only was using the xmlrpc code so I didn't link the json and amf code, but that only reduced the size by ~10K.

Comment by akeemphilbert, Dec 02, 2007

@tommyw13 the file size could be attributed to the use of HTTPService code. I will look at file size options in future releases.

@dorkiedorkfromdorktown the use of of AMFPHP should be the same as using the xml-rpc piece, only difference being the use of AMF0Object instead of XMLRPCObject

Comment by 735115, Dec 04, 2007

In a Cairngorm delegate, how do I reference my XMLRPCObject? I've tried it as such:

import com.adobe.cairngorm.business.ServiceLocator; ... service = ServiceLocator.getInstance().getHTTPService("loadDataService");

But ServiceLocator?? only has getHTTPService, getWebService, and getRemoteObject functions. How do I reference this XMLRPCObject?

In MXML, I have it defined the object as:

<ak33m:XMLRPCObject id="loadDataService" endpoint="http://localhost:8080"/>

Thanks!

Comment by 735115, Dec 04, 2007

Never mind, I figured it out. ServiceLocator? also has a generic getService() function, which works with XMLRPCObject:

service = ServiceLocator.getInstance().getService("loadDataService");

Comment by christopher.brind, Jan 07, 2008

Hi, I get a security error when I try and use this to access the XMLRPC service on Livejournal.com. After reading up it seems that SWFs are not allowed to make connections to URLs that the SWF wasn't loaded from without some special setup on the remote server (which won't happen in my case) or by using a proxy.

Any recommendations on how to do this with your library?

Thanks in advance.

Comment by evan.kaufman, Feb 06, 2008

In regard to filesize, and the use of the less than reliable HTTPService, you could always use the as3httpclient package, by Abdul Qabiz. It's an HTTP client written entirely in AS3, and hosted here on google code: http://code.google.com/p/as3httpclient/

While only the SVN version seems to be up to date, it does seem to work well from my (admittedly limited) testing.

Comment by elliott.hoffman, Mar 05, 2008

Hello, my HTTP headers show that I am sending a Content-Type of application/xml. Is there a way in your library to send Content-Type of text/xml instead? It is required for the service I am trying to access, and I did not find it in the documentation.

Thank you

Comment by akeemphilbert, Apr 16, 2008

@elliott.hoffman the build that is in svn has the correct content type header. Its been a while since I updated the featured download. For the latest and greatest get the swc that is in svn

@evan thanks. I'll check it out. I have been meaning to get rid of the HTTPService use but so little time.

Comment by BruceTEckel, Apr 23, 2008

I'm getting a "Illegal Override of XMLRPCObject" when I do something as simple as this:

<?xml version="1.0" encoding="utf-8"?> <mx:WindowedApplication? xmlns:mx="http://www.adobe.com/2006/mxml" xmlns:ak33m="http://ak33m.com/mxml"> <ak33m:XMLRPCObject id="server" endpoint="http://localhost:7080"/> </mx:WindowedApplication?>

Comment by BruceTEckel, Apr 24, 2008

I don't get the error message with earlier versions.

Comment by akeemphilbert, Apr 26, 2008

@BruceTEckel I've been unable to replicate this issue. Changes occured in the XMLRPCSerializer and I am not sure where that error would even stem from. Are you trying to swap the new version of the library out in an existing project?

Comment by dshe...@americanri.com, Apr 30, 2008

We justed started using the latest release of as3-rpclib and we are getting the same error as Bruce ("Illegal Override of XMLRPCObject"). The errors are coming from two functions in 'XMLRPCObject.as'. Flex error panel is saying that the functions - 'setCredentials' & 'setRemoteCredentials' are "Overriding a function that is not marked for override".

Are the older versions of as3_rpclib available for download?

Comment by david.helms, May 05, 2008

Looking for flex support for json-rpc. Is this supported and if so, what version did you target? Thanks. david

Comment by jamesyjhu, May 10, 2008

For people who are using Flex Builder 3, and have the "Illegal Override of XMLRPCObject" error, you need to:

1) import the project into flex builder 3

2) it'll tell you that the project was made in previous version of flex builder. Select the "default" version (which is Flex 3)

3) Open up XMLObject.as, look for "setCredentials" and replace the function signature with: override public function setCredentials (username:String,password:String,charset:String = null):void

4) right below, find "setRemoteCredentials" and replace the function signature with: override public function setRemoteCredentials (username:String,password:String,charset:String = null):void

5) build it (automatically) and enjoy!

Comment by akeemphilbert, May 16, 2008

@dshe yes older versions are available for download on the download page. Just change the drop down on the download page to Deprecated or All Dowloads. The error seems to be stemming from Flex 3 incompatibility (which I don't have :( )

@jamesyjhu thanks for offering the fix. I am unable to a Flex 3 build because I don't have it. If you can provide a Flex 3 build of the library so I can put it up on the downloads page that would be great. Thanks in advance

Comment by sg...@lanctr.com, May 25, 2008

Hitting your xml name space isn't working. In FB3 I'm getting "Could not resolve <ak33m:XMLRPCObject> to a component implementation".

Comment by thesamet, Jun 28, 2008

Good work! It seems that XMLRPCSerialize encodeString does not work well if the string contains special characters like '<', it needs to be escaped somehow.

Comment by nevgeniev, Jun 29, 2008

I have to confirm issue with namespace -- "Could not resolve <ak33m:XMLRPCObject> to a component implementation"

Comment by senichas, Jul 09, 2008

Can you post example code of connect and call server methods for FMS3? Thank you.

Comment by matko.kvesic, Jul 11, 2008

Solution without .swc file

1. put the namespace for example > xmlns:ak33m="com.ak33m.rpc.xmlrpc." < in Application

2. in the root of your project put > com/ak33m/rpc/xmlrpc + files under it < structure

3. now you can instantiate <ak33m:XMLRPCObject>

Matko Kvesic

Comment by therexley, Jul 28, 2008

For people who are using Flex SDK 3, and have the "Illegal Override of XMLRPCObject" error, you need to:

1) Open up XMLRPCObject.as, look for "setCredentials" and replace the function signature with: override public function setCredentials (username:String,password:String,charset:String = null):void

2) In the same file, find "setRemoteCredentials" and replace the function signature with: override public function setRemoteCredentials (username:String,password:String,charset:String = null):void

3) Rebuild as3-rpclib.swc library, for example on Windows:

d:\flex\bin\compc.exe -source-path .\src -namespace http://ak33m.com/mxml .\src\manifest.xml -include-namespaces http://ak33m.com/mxml -output=.\bin\as3-rpclib.swc

Comment by lowpitch, Jul 29, 2008

Does anyone know if it's possible to automatically cast a value returned from an XML-RPC method to a particular datatype, for example a Value Object? Say for example I've called a method which returns an array of messageboard posts, and I have a Value Object class which represents a messageboard post, is there any way to automatically connect the two? How things stand, I'm receiving an array of Objects.

Currently, I'm iterating through the result array and creating each messageboard post manually, setting each and every property manually based on values in the current Object, but it feels like there should be a nicer way of achieving this.

Any ideas? Cheers, toby

Comment by stickmanlabs, Aug 14, 2008

Can anyone show an example of how I would use this in a flash cs3 project using the json? I think this is the only thing out there but am not sure how to use this thing?

Comment by marc.silverman, Feb 06, 2009

In case it is useful for anyone, if you need to pass something as a Hashtable or something similar, create a class that implements the IXMLRPCStruct interface. I created a class hashtable, added an Array to the class, and returned the through getProperties (the function for the IXMLRPCStruct interface).

In addition, in the version of the source I downloaded, the condition for the byte to base64 encoder wasn't there. I added

else if (tobject is ByteArray?) {
txmllist = encodeBase64(tobject);
}

at the end of encodeObject in XMLRPCSerializer and it worked great.

Thanks to everyone who built this library.

Comment by mkaffel, Feb 20, 2009

Can I have an exemple of the implementation of a struct with the interface IXMLStruct ?

Thanks

Comment by willkriski, Apr 10, 2009

Why isn't this fixed to work with Flex 3? :) getting VerifyError?: Error #1053: Illegal override of XMLRPCObject in com.ak33m.rpc.xmlrpc.XMLRPCObject.

Comment by vanjan, Jul 23, 2009

I'm getting the same error

Comment by vanjan, Jul 23, 2009

Sign in to add a comment
Hosted by Google Code