Invoking another server component’s methods

EAServer allows the methods of one server component to call methods of another server component. The other server component does not need to be another PowerBuilder component; it can be implemented in any language supported by EAServer.

Accessing a component in the current server

To access methods of another EAServer component in the current server, you can use the Connection object to communicate with the component, just as you would from a PowerBuilder client. Alternatively, you can use the transaction service context object that PowerBuilder provides called TransactionServer. The TransactionServer interface provides a method called CreateInstance that allows you to access other components that are available locally. CreateInstance uses the same user and password information that applies to the component from which it is called.

Before you can use the transaction context service, declare a variable of type TransactionServer and call the GetContextService function to create an instance of the service. You must use a proxy object for your intercomponent calls. Without a proxy object, the TransactionServer object cannot obtain the correct method names of the component you are calling. For information on creating a proxy object for EAServer components, see “Generating EAServer proxy objects”.

Example In the Activate event for a component, you can call GetContextService to instantiate the TransactionServer service:

// Instance variable:
// TransactionServer ts

Integer rc
rc = this.GetContextService("TransactionServer", ts)
IF rc <> 1 THEN
   // handle the error
END IF

In one of the component methods, you can then call CreateInstance to instantiate the second component and call one of its methods. Your application should include a proxy for the second component:

// Instance variable for the second component:
// nvo_comp2 mycomp2 
Integer rc
rc = ts.CreateInstance(mycomp2, "mypackage/nvo_comp2")
IF rc <> 0 THEN
   // handle the error
ELSE
   mycomp2.method1()
END IF

Accessing a component in a different server

The procedure for accessing a server component on a different server is essentially the same as the procedure for accessing a server component from a PowerBuilder client. To access an EAServer component on a different server, create a Connection object, set properties for the Connection object, and call ConnectToServer.

Accessing an EJB component

A PowerBuilder component can access an EJB component using the Lookup method of either the Connection or TransactionServer objects. The Lookup method on the TransactionServer object has an optional third argument you can use to specify the name of the home interface. You use this argument only if the home interface name does not follow typical naming conventions.

Example This script instantiates the Cart component and invokes several component methods. In this example, the second argument to the Lookup method specifies the component name as well as the EAServer package name:

//Instance variable:
//Connection myconnect

CartHome MyCartHome // EJB's home interface
Cart MyShoppingCart // EJB's remote interface
TransactionServer ts
long ll_result

This.GetContextService("TransactionServer", ts)

//Get the home interface
ll_result = &
ts.Lookup(MyCartHome, "Shopping/Cart")


//Get a reference to Cart component's business logic
MyShoppingCart = MyCartHome.Create()

//Use the shopping cart
MyShoppingCart.AddItem(66)
MyShoppingCart.Purchase()

For information about accessing EJB components from PowerBuilder clients, see “Invoking an EJB component method”.

Component-demarcated transactions

EAServer components marked as OTS style can create, control, and obtain information about EAServer transactions using functions of the CORBACurrent context service object. The CORBACurrent object provides most of the methods defined for the CORBA Current interface.

For more information, see “Client- and component-demarcated transactions”.