RPC HELP Tutorial Step 3

From VistApedia
Jump to: navigation, search

RPC Broker Help Home

Tutorial Home

Tutorial: Step 3 -- Establish Broker Connection

Now that your application can determine the appropriate RPC Broker server and port to connect to (Step 2), you can add code to establish a connection to the designated RPC Broker server from your application. The act of establishing a connection leads the user through signon. If signon succeeds, a connection is established.

To establish a connection from your application to a RPC Broker server:

  • Add code to Form1's OnCreate event handler. The code should:
    • Set brkrRPCBroker1's Connected property to True (inside of an exception handler try...except block). This will cause an attempt to connect to the RPC Broker server.
    • Check if an EBrokerError exception is raised. If this happens, connection failed, and your code should inform the user of this and terminate the application.
    • The OnCreate event handler should now look like:
   procedure TForm1.FormCreate(Sender: TObject);
   var ServerStr: String;
     PortStr: String;
   begin
     // Get the correct port and server from the Registry.
     if GetServerInfo(ServerStr,PortStr)<> mrCancel then begin
       {connectOK begin}      
       brkrRPCBroker1.Server:=ServerStr;
       brkrRPCBroker1.ListenerPort:=StrToInt(PortStr);
       // Establish a connection to the RPC Broker server.
       try
         brkrRPCBroker1.Connected:=True;
       except
         On EBrokerError do begin
           {error begin}
           ShowMessage('Connection to server could not be established!');
           Application.Terminate;          
         end;  {error end}      
       end; {try end}      
     end {connectOK end}
     else begin
       Application.Terminate;
     end;
   end;

NOTE Every call that invokes an RPC Broker server connection should be done in an "exception handler" try...except block, so that EBrokerError exceptions can be trapped.

  • Save, compile and run your application. It should connect to the VistA M Server returned by the GetServerInfo function. You may be prompted to sign on with Access and Verify codes (unless Auto Signon is enabled, and you are already signed on). If you can connect successfully, your application will run (at this point, it is just a blank form). Otherwise, troubleshoot your RPC Broker connection until you can get your application to connect.
  • If the server system defined in your Registry is not your development system (the one on which you will create RPCs for this application), update your Registry using the ServerList.EXE program so that your application will connect to the proper VistA M Server.

Now that your application can establish a connection to the end-user's server system, you can go about retrieving data from the VistA M Server.

In the next steps of the tutorial, you will create a custom RPC that retrieves a list of all of the terminal types on the VistA M Server and call that RPC from your application.

PREV: Step 2: Get Server/Port

NEXT: Step 4: RPC Routine to List Terminal Types