Expand my Community achievements bar.

Dive into Adobe Summit 2024! Explore curated list of AEM sessions & labs, register, connect with experts, ask questions, engage, and share insights. Don't miss the excitement.

Simple RPC with RemoteObject

Avatar

Level 2
Hello,



I am a newbie and I am trying a simple application to test
RPC using RemoteObject. My application takes a name from a text
input field and prints the welcome greeting in a text area.



The method to execute in my RemoteObject is a goofy method
that takes a person's name and returns the String welcoming the
person.



Here is the method.



package rpc.playerinfo;

public class PlayerService {

public String printThis(String name) {

return "Welcome to " + name;

}

}





I've added a destination representing this remote object in
the remote-config.xml file.

<destination id="PlayerDB">

<properties>

<source>rpc.playerinfo.PlayerService</source>

</properties>

</destination>





My MXML code is given below :



<?xml version="1.0" encoding="utf-8"?>

<mx:Application xmlns:mx="
http://www.adobe.com/2006/mxml"
layout="absolute">

<mx:Script>

<![CDATA[

import rpc.playerinfo.*;



private function fillTxt(b: String):void{

mainTxt.text = b;

}

]]>

</mx:Script>



<mx:RemoteObject id="play" destination="PlayerDB">

<mx:method name="printThis" concurrency="last"
result="fillTxt(event.result as String)"/>

</mx:RemoteObject>



<mx:Panel title="Get Player">

<mx:TextArea id = "mainTxt"/> <!-- This is where
the output goes-->

<mx:TextInput id="txtNumber"/> <!-- This is where
the text is input-->

<mx:Button label="i like to print"
click="play.printThis(txtNumber.text)" /> <--Call the remote
object here -->

</mx:Panel>

</mx:Application>





When I try to run it, I get the following error, when I click
the button.





[RPC Fault faultString="[MessagingError message='Unknown
destination 'PlayerDB'.']" faultCode="InvokeFailed"
faultDetail="Couldn't establish a connection to 'PlayerDB'"]

at mx.rpc::AbstractInvoker/
http://www.adobe.com/2006/flex/mx/internal::invoke()

at mx.rpc.remoting.mxml::Operation/
http://www.adobe.com/2006/flex/mx/internal::invoke()

at mx.rpc.remoting::Operation/send()

at Function/
http://adobe.com/AS3/2006/builtin::apply()

at mx.rpc.remoting.mxml::Operation/send()

at Function/
http://adobe.com/AS3/2006/builtin::apply()

at mx.rpc::AbstractService/
http://www.adobe.com/2006/actionscript/flash/proxy::callProperty()

at RPCDataService/___Button1_click()





Please help this newbie. Thank you.
11 Replies

Avatar

Former Community Member
Hi, I tried the same example and it worked for me. Are you
sure you're editing the right remoting-config.xml ?

Avatar

Level 2
Thanks matamel,



I don't know how it can work on your computer and not on
mine. Yes, I am modifying the right configuration files.



My full remoting-config file looks like this :



<?xml version="1.0" encoding="UTF-8"?>

<service id="remoting-service"

class="flex.messaging.services.RemotingService"

messageTypes="flex.messaging.messages.RemotingMessage">



<adapters>

<adapter-definition id="java-object"
class="flex.messaging.services.remoting.adapters.JavaAdapter"
default="true"/>

</adapters>



<default-channels>

<channel ref="my-amf"/>

</default-channels>





<destination id="PlayerDB">

<properties>

<source>rpc.playerinfo.PlayerService</source>

</properties>

</destination>



</service>





Also, my web.xml is pretty empty. Anything need to be there ?



<?xml version="1.0" encoding="ISO-8859-1"?>

<!DOCTYPE web-app

PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application
2.3//EN"

"
http://java.sun.com/dtd/web-app_2_3.dtd">

<web-app>

<!-- BalancerFilter definition -->

</web-app>



Also, I have two web applications - Flex and rpcdataservice.
Inside my rpcdataservice I have a web-inf folder, inside which I
have another flex subdirectory. I am modifying the
remote-config.xml file in my flex subdirectory inside my
rpcdataservice web application. I am NOT modifying it in the flex
web application (The Flex root).



Also,

Should I have a correponding actionscript file for my Java
class ? I was under the assumption that those are required only if
I am using them as data types. Here the return type is just a
String.



Thanks for your help.

Avatar

Former Community Member
No, you don't need need Actionscipt files in this case. Your
remoting-config.xml file is correct but maybe your application
tries to pick remoting-config.xml from the Flex folder? Why don't
you define PlayerDB in WEB-INF/ of Flex folder as well and see if
that makes a difference?

Avatar

Level 2
Tried everything, doesn't work.



Even removed flex and flex-admin webapps from Tomcat. Just
have rpcdataservice webapp and inside that the Flex subfolder with
the right configuration files.



Also, I used the build.bat (got it from flex samples) to
build the .swf file from .mxml file.



@echo off

SET OPTS=-use-network=false

for /R . %%f in (*.mxml) do ..\..\bin\mxmlc.exe %OPTS% "%%f"



I'm sure this has nothing to do with it, but I tried
everything else already



Thanks Matamel.

Avatar

Former Community Member
Hmm. I don't know what could be the problem but these are
some things I'd try myself:



1- Can you define and use the remote object from flex or
flex-admin apps?

2- Can you use other types of destinations in rpcdataservice
app? (look into messaging-config.xml, proxy-config.xml and
data-management.xml config for other types of destinations)

Avatar

Level 2
And the plot thickens.



I removed flex, flex-admin directories, and kept just the
rpcdataservice (my app) as the only webapp under Tomcat. What I see
is that if I launch .mxml from the browser, it works, but when I
launch the .swf file it complains about 'unknown destination'.



I compiled the .mxml into .swf frm command-line using the
batch file I mentioned in the earlier message.



So .mxml works, but .swf doesn't work. Again I am launching
both the files from the browser.



Thanks for your patience.

Avatar

Former Community Member
What happens when you try to launch the flex-admin swf file
(console.swf I think)? Do you get the same type of error?

Avatar

Former Community Member
By the way, when you compile mxml yourself, make sure you use
--compiler.services <path_to_services-config.xml>. This
points the compiler to your services configuration file and that
way all the destination information gets compiled into the swf.

Avatar

Level 2
>>By the way, when you compile mxml yourself, make sure
you use --compiler.services <path_to_services-config.xml>.



That works - now .the swf and mxml both work.



Thanks so much for your help, matamel.

Avatar

Former Community Member
hi arkcto ,. i also have same problem as well

i have created a Flex 2 application and compiled a some java
class..

i was using remoteobj to connect those java class



but i also got this error

RPC Fault faultString="[MessagingError message='Unknown
destination 'PlayerDB'.



so that , what can i do .. thank ..

Avatar

Former Community Member
Did you specify a -services command line argument for the
compiler and set

its value to the path to your
/WEB-INF/flex/services-config.xml file?



Pete