Creating and using a named server

Using your own named server involves these steps:

  1. Define the objects you will access.

  2. Build the runtime libraries for those objects.

  3. Register your server in the registry.

  4. 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:

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.

  1. 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.

  2. 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
    
  3. 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
    
  4. 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)
    
  5. 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