Class org.as2lib.io.conn.local.client.LocalClientServiceProxy

org.as2lib.core.BasicClass
   +--org.as2lib.io.conn.core.client.AbstractClientServiceProxy
      +--org.as2lib.io.conn.local.client.LocalClientServiceProxy

Implemented Interfaces

ClientServiceProxy

Description

LocalClientServiceProxy handles client requests to a certain service and its responses.

Example: var client:LocalClientServiceProxy = new LocalClientServiceProxy("local.as2lib.org/myService"); var callback:MethodInvocationCallback = client.invoke("myMethod", ["firstArgument", "secondArgument"]); callback.onReturn = function(returnInfo:MethodInvocationReturnInfo):Void { trace("myMethod - return value: " + returnInfo.getReturnValue()); } callback.onError = function(errorInfo:MethodInvocationErrorInfo):Void { trace("myMethod - error: " + errorInfo.getException()); }

It is also possible to call the method directly on the proxy. But you can't type the proxy then. var client = new LocalClientServiceProxy("local.as2lib.org/myService"); var callback:MethodInvocationCallback = client.myMethod("firstArgument", "secondArgument");

The neatest way is to use LocalClientServiceProxyFactory to get a proxy for a service interface or class, which enables compiler checks. For more information on this refer to the LocalClientServiceProxyFactory class.

If the return value is not of type Number, Boolean, String or Array that are converted directly into the appropriate type you must do the following to receive a value of correct type. Otherwise the return value will be an instance of type Object that is populated with the instance variables of the sent object. Note that this must be done on the client as well as on the server and the 'symbolId' in this case "MyClass" must be the same. Object.registerClass("MyClass", MyClass);

The received object will now be of correct type. But you still have to be aware of some facts:
Flash creates a new object in the background and sets the instance variables of the sent instance to the new object. It then registers this object with the appropriate class (if registered previously) and applies the constructor of that class to the new object passing no arguments. This means if the constructor sets instance variables it overwrites the ones set previously by undefined.

Method Index

new LocalClientServiceProxy()

generateResponseServiceUrl(), getUrl(), invokeByNameAndArgumentsAndCallback()

Inherited from AbstractClientServiceProxy

invoke(), invokeByName(), invokeByNameAndArguments(), invokeByNameAndCallback()

Inherited from BasicClass

toString()

Constructor Detail

LocalClientServiceProxy

public function LocalClientServiceProxy(url:String)

Constructs a new LocalClientServiceProxy instance.

Parameters

urlthe url of the service

Throws

IllegalArgumentExceptionif url is null, undefined or an empty string

Method Detail

generateResponseServiceUrl

static public function generateResponseServiceUrl(serviceUrl:String, methodName:String):String

Generates the response url for a service.

The response url is composed as follows:

theServiceUrl.theMethodName_Return_theIndex

If the passed-in methodName is null, undefined or an empty string the response url will be composed as follows:

theServiceUrl_Return_theIndex

index is a number from 0 to infinite depending on how many responses are pending.

Parameters

serviceUrlthe url to the service
methodNamethe name of the responsing method

Return

the generated response url

Throws

IllegalArgumentExceptionif the passed-in serviceUrl is null, undefined or an empty stirng

getUrl

public function getUrl(Void):String

Returns the url of the service this proxy invokes methods on.

The returned url is never null, undefined or an empty string.

Return

the url of the service this proxy invokes methods on

invokeByNameAndArgumentsAndCallback

public function invokeByNameAndArgumentsAndCallback(methodName:String, args:Array, callback:MethodInvocationCallback):MethodInvocationCallback

Invokes the method with passed-in methodName on the 'remote' service, passing the elements of the passed-in args as parameters and invokes the appropriate method on the passed-in callback on response.

The response of the method invocation is delegated to the appropriate method on the passed-in callback. This is either the onReturn when no error occured, or the onError method in case something went wrong.

If the passed-in callback is null a new MethodInvocationCallback instance will be created and returned. It is possible to still set the callback methods there, after invoking this method.

Parameters

methodNamethe name of the method to invoke on the 'remote' service
argsthe arguments that are passed to the method as parameters
callbackthe callback that handles the response

Return

either the passed-in callback or a new callback if null

Throws

IllegalArgumentExceptionif the passed-in methodName is null, undefined or an empty string

Specified By

invokeByNameAndArgumentsAndCallback() in org.as2lib.io.conn.core.client.ClientServiceProxy