Using your own named server involves these steps:
Define the objects you will access.
Build the runtime libraries for those objects.
Register your server in the registry.
Write code in the client that connects to your server, creates objects, and accesses their methods and properties.
Defining user objects for use in a named server is the same as for PowerBuilder.Application.
For information, see “Creating the user objects you will access”.
Building runtime libraries for use in a named server is the same as for PowerBuilder.Application.
For information, see “Building runtime libraries”.
You can use the Automation Server project wizard to register your server, as described in “Registering the object”.
To register your server rather than a single user object, select PowerBuilder.Application as the component. Proceed as described in “Registering the object” and install the registry update file in the registry. You do not need to create a type library file for a named server.
A client application that wants to establish a session with your named server needs code to:
Connect to the server
Instantiate objects
Access those objects
The following steps with code examples illustrate how to do it. The examples are client code for PowerBuilder. All the steps of the process should be accompanied by error checking because there are any number of reasons why server sessions can fail.
Declare one OLEObject variable for your server. Declare additional OLEObject variables for each object you will create:
OLEObject ole_server, ole_analyze
If you want to handle errors in the OLEObject ExternalException and Error events, use a user object inherited from OLEObject instead.
Start the automation server and check that the connection was established. A status of 0 indicates success:
ole_server = CREATE OLEObject
li_status = ole_server.ConnectToNewObject & ("MyCompany.MyServer")
IF li_status < 0 THEN
MessageBox("No Server", &
"Can't connect to the server.")
RETURN
END IF
Create the first object you want to use and check for success. Specify the object’s name as defined in the library:
ole_analyze = &
ole_server.CreateObject("uo_analyze")
IF IsNull(ole_analyze) THEN
MessageBox("No Object", &
"Cannot create object uo_analyze.")
RETURN
END IF
Access functions or properties of the object using automation syntax. (These properties and methods are hypothetical.)
ld_avg = ole_analyze.uof_average()
ole_analyze.Projection = TRUE
li_status = ole_analyze.uof_RTFReport(REF ls_rpt)
Disconnect from the server and destroy the objects when you are done. (Exiting your application also accomplishes this.)
DESTROY ole_analyze
ole_server.DisconnectObject()
DESTROY ole_server