Programming Example: Revised Code for Simple Service Example

This section will show you how to create a simple cross-application service based on the "Sample" service created in an earlier section (see Programming Example: Create a Simple Service).

First, create a new standard application and copy the "Sample" service code into the new application. Compile this and make sure that it works.

You now have two identical applications, each of which has a different application GUID (look in the GDI.WIF file in each application's directory to verify this). We will now change the second application so that the "Sample" service works cross-application.

Add a "RemoteGUID" variable to the SampleService declarations.

{====================== SampleService ==========================}

{ This service maintains a simple synchronizable state and      }

{ properly supports all entry points required by RPC Manager    }

{ for correct operation.                                        }

{===============================================================}

[

    . 

    . 

    . 

    RemoteGUID { GUID of the master application }; 

    . 

    . 

    . 

]

Set the "RemoteGUID" variable to the application GUID of the first application. Do this before calling "\RPCManager\Register". Note that the binary form of the GUID is used. You can obtain the GUID from the first application's GDI.WIF file.

Init [

    If 1 Main; 

    [ 

          RemoteGUID = GetGUID(1{bin}, "e7a82aa4-21b2-4303-b7d7-1d66353dab35"); 

          {***** Register the sample service with RPC Manager. *****} 

          RPCStatus = \RPCManager\Register(SvcName, Invalid, Invalid, 

          Invalid, \RPC_SYNC_MODE); 

    ] 

]

Include a fourth parameter to GetServerChanges. This is only required if you are doing x-app RPC. It is the GUID of the application that is synchronizing to the master service instance. This parameter must be called RemoteGUID (case insensitive), so that PackRPC and SetDivert will pick it up and work correctly.

{=================== GetServerChanges ==============================}

{ Called by RPC Manager during startup sync, on a server, to get the package of RPCs which create a synchronizable state on the client which is in step with the server. }

{===================================================================}

GetServerChanges

(

RevisionInfo { Revision info from GetClientRevision call 

made on synchronizing client - unused here }; 

PackStreamRef { Pointer to var to receive changes }; 

ClientName { Name of client }; 

RemoteGUID { The GUID of the app synchronizing to me }; 

)

The "Sample" service in your second application is now a slave, and will remain as a synchronized client to the master "Sample" service in your first application.