Creating and using a named server
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.
Creating the user objects you will access
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
Building runtime libraries for use in a named server is the
same as for PowerBuilder.Application.
For information, see “Building runtime libraries”.
Registering the server
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.
Writing client code that accesses the server
and user objects
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:1OLEObject ole_server, ole_analyzeIf 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:1ole_server = CREATE OLEObject1li_status = ole_server.ConnectToNewObject &<br /> ("MyCompany.MyServer")1IF li_status < 0 THEN1MessageBox("No Server", &1"Can't connect to the server.")1RETURN1END IF - Create the first object you want to use and check
for success. Specify the object’s name as defined in the
library:1ole_analyze = &1ole_server.CreateObject("uo_analyze")1IF IsNull(ole_analyze) THEN1MessageBox("No Object", &1"Can't create object uo_analyze.")1RETURN1END IF - Access functions or properties of the object using
automation syntax. (These properties and methods are hypothetical.)1ld_avg = ole_analyze.uof_average()1ole_analyze.Projection = TRUE1li_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.)1DESTROY ole_analyze1ole_server.DisconnectObject()1DESTROY ole_server