Your achievements

Level 1

0% to

Level 2

Tip /
Sign in

Sign in to Community

to gain points, level up, and earn exciting badges like the new
Bedrock Mission!

Learn more

View all

Sign in to view all badges

Simple RPC with RemoteObject

arkcto
Level 2
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
Mete_Atamel
Level 4
Level 4
Hi, I tried the same example and it worked for me. Are you
sure you're editing the right remoting-config.xml ?
arkcto
Level 2
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.
Mete_Atamel
Level 4
Level 4
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?
arkcto
Level 2
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.
Mete_Atamel
Level 4
Level 4
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)
arkcto
Level 2
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.
Mete_Atamel
Level 4
Level 4
What happens when you try to launch the flex-admin swf file
(console.swf I think)? Do you get the same type of error?
Mete_Atamel
Level 4
Level 4
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.

arkcto
Level 2
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.
ben_ktg
Level 1
Level 1
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 ..

Not applicable
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