Posts filed under 'AMF'

How to set up and get WebOrb communication with Flex 2 with no service-config.xml

So at work we are experimenting with WebOrb to ditch XML. No for good but definatly when there will be a lot of parsing. Anyway, our PHP Programmer downloaded WebOrb and we looked at the examples but the example were either banking on you having previous Flex Data Services experience or they were not that good in my opinion. The most crucial info was not even on the tutorial application page. So I’m going to walk you through the tutorial with the modification I used to get it working from various Google Searches. Mainly no service-cofig.xml.

  1. Ok, first thing is go to WebOrb’s website http://www.themidnightcoders.com/weborb/php/index.htm
    I’m using the PHP version, and make sure you have PHP5.
  2. Upload it to your server on put it in you localhost folder. We have it in a folder called “WebOrb” (http://YOUR_SITE/WebOrb)
  3. Create a new project in Flex.
  4. Go to the WebOrb tutorial. http://www.themidnightcoders.com/weborb/php/gettingstarted.htm skip down to the heading CONFIGURATION – FLEX BUILDER follow those directions. The remote config on our set up is http://YOUR_SITE/WebOrb/Weborb/WEB-INF/flex/remote-config.xml The last direction on the site is the server code (PHP) that goes in the Services folder located in http://YOUR_SITE/WebOrb/Services/InfoServices (with our current set-up)
  5. Now let’s go to another page and get the info on how this is connection to the service because that tutorial told me nothing about service-cofig.xml. Invoking PHP objects w/ Remote Object.
  6. don’t worry about this skip it (if you do worry go to the remote-config.xml to check it out http://YOUR_SITE/WebOrb/Weborb/flex):< <destination id=”destination-name”>
    <properties>
    <source>Your.PHP.ClassName</source>
    </properties>
    </destination>we will be using a GenericDestination which is already in the remote-config.xml:<destination id=”GenericDestination”>
    <properties>
    <source>*</source>
    </properties>
    </destination>

    the source tag will be filled in the Flex code.
  7. now we will fill out the mxml RemoteObject:
    < mx:RemoteObject id="InfoServiceObj" destination="GenericDestination"
    endpoint="http://YOUR_SITE/WebOrb/Weborb/index.php" fault="onFault(event)" showbusycursor="true" fault="onFault(event)">
    < mx:method name="getComputerInfo" result="onResult(event)">
    mx:RemoteObject>
    
    endpoint="http://YOUR_SITE/WebOrb/Weborb/index.php" and destination="GenericDestination" are what make this RemoteObject flexible. All you have to do is change you destination and your ready to go for another service. Endpoint is like you gateway in AMFPHP (to all the classes of weborb)
  8. Lastly here are the handlers for the modified example.mxml, dump this in over the old scripts
    import mx.rpc.remoting.*;
    import mx.controls.*;
    import mx.rpc.events.*
    
    public function onCreationComplete():void
    {
    InfoServiceObj.getComputerInfo.addEventListener("result", onResult);
    
    }
    
    public static function onFault(event:FaultEvent):void
    {
    Alert.show(event.fault.faultString, 'Error');
    }
    
    private function onResult(event:ResultEvent):void
    {
    var computerInfo:Object = event.result;
    currentUserText.text = computerInfo.currentUser;
    processIdText.text = computerInfo.phpProcessId;
    osText.text = computerInfo.operatingSystem;
    phpVersionText.text = computerInfo.phpVersion;
    invokeButton.enabled = true;
    
    }
    
    private function getInfo():void
    {
    invokeButton.enabled = false;
    currentUserText.text = "";
    processIdText.text = "";
    osText.text = "";
    phpVersionText.text = "";
    
    InfoServiceObj.getComputerInfo();
    }
    
    and put a click handler on the button click="getInfo()"

here is the code I hope it helps:

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute"
creationComplete="onCreationComplete()">

<mx:Script>
<![CDATA[
import mx.rpc.remoting.*;
import mx.controls.*;
import mx.rpc.events.*

public function onCreationComplete():void
{
InfoServiceObj.getComputerInfo.addEventListener("result", onResult);

}

public static function onFault(event:FaultEvent):void
{
Alert.show(event.fault.faultString, 'Error');
}

private function onResult(event:ResultEvent):void
{
var computerInfo:Object = event.result;
currentUserText.text = computerInfo.currentUser;
processIdText.text = computerInfo.phpProcessId;
osText.text = computerInfo.operatingSystem;
phpVersionText.text = computerInfo.phpVersion;
invokeButton.enabled = true;

}

private function getInfo():void
{
invokeButton.enabled = false;
currentUserText.text = "";
processIdText.text = "";
osText.text = "";
phpVersionText.text = "";

InfoServiceObj.getComputerInfo();
}
]]>
</mx:Script>
<mx:RemoteObject destination="GenericDestination" source="InfoService" id="InfoServiceObj" endpoint="http://YOUR_SITE/WebOrb/Weborb/index.php" fault="onFault(event)" showBusyCursor="true">
<mx:method  name="getComputerInfo" result="onResult(event)" />
</mx:RemoteObject>
<mx:Panel x="10" y="10" width="329" height="189" layout="absolute" title="Info Service Example">
<mx:Label x="10" y="10" text="Current user:"/>
<mx:Label x="10" y="36" text="PHP Process ID:"/>
<mx:Label x="10" y="62" text="OS/Architecture:"/>
<mx:Label x="10" y="88" text="PHP Version:"/>
<mx:TextInput x="113" y="8" width="186" editable="false" id="currentUserText"/>
<mx:TextInput x="113" y="34" width="186" editable="false" id="processIdText"/>
<mx:TextInput x="113" y="60" width="186" editable="false" id="osText"/>
<mx:TextInput x="113" y="86" width="186" editable="false" id="phpVersionText"/>
<mx:Button id="invokeButton" x="166" y="116" label="Get Computer Info" click="getInfo()" />
</mx:Panel>

</mx:Application>

2 comments October 1st, 2007


    Blog Calendar

    March 2010
    M T W T F S S
    « Jun    
    1234567
    891011121314
    15161718192021
    22232425262728
    293031  

    Posts by Month

    Posts by Category