Try OpenEdge Now
skip to main content
.NET Open Clients
Using the Open Client .NET OpenAPI to Directly Access the AppServer : Sample .NET OpenAPI code : Single-run/singleton procedure example
 

Single-run/singleton procedure example

The following example shows a user-defined function defined by a procedure called CustomerInfo.p.
User-defined function defined by CustomerInfo.p
FUNCTION GetTotalOrdersByNumber RETURNS INTEGER (custNum AS INTEGER, threshold AS DECIMAL):
...
END.
...
The version of CustomerInfo.p in Persistentprocedure sample cannot be run as a single-run (or singleton) because it has a parameter in the main block. Creating another internal procedure to set CustNum would also not work, because a single-run procedure is deleted from the AppServer after each call. Context must be established for each call. So in User-defined function defined by CustomerInfo.p CustNum is passed as a parameter to the user-defined function GetTotalOrdersByNumber instead.
The following OpenAPI code runs CustomerInfo.p as a single-run procedure and then calls its user-defined function. The code also shows how to access the procedure type using the ProcedureType parameter. A singleton procedure can be run in the same way, with ProcedureType.Singleton substituted into the CreatePO method.
OpenAPI code to run the single-run procedure
namespace BigOrderInfoClient  {

  using Progress.Open4GL;
  using Progress.Open4GL.Proxy;
  using Progress.Open4GL.ProcedureType;

  public class samplecode         {

    public static void SingleRunProcedure( )  {
      // Connect to the AppServer
      Connection myConn = new Connection
                          ("AppServer://localhost/asbroker2", "", "", "");
      OpenAppObject openAO = new OpenAppObject(myConn, "mySvc");

      // Run procedure as single-run
      OpenProcObject openPO = openAO.CreatePO("OrderInfo/CustomerInfo.p",
                                              ProcedureType.SingleRun);

      // Display procedure type using ProcedureType parameter
      System.Console.Out.WriteLine("Procedure object procedure type: "
                         + dynPO.ProcedureType);

      // Call UDF
      // First set up parameters
      System.Int32 custNum = 3;
      System.Decimal retVal;
      int Threshold = 1000;

      // Set up input parameters
      ParamArray parms = new ParamArray(2);
      parms.AddInteger(0, custNum, ParamArrayMode.INPUT);
      parms.AddDecimal(1, Threshold, ParamArrayMode.INPUT);

      // Set up return type
      parms.ReturnType = Parameter.PRO_DECIMAL;

      // Run UDF
      openPO.RunProc("GetTotalOrdersByNumber", parms);

      // Get return value
      retVal = (System.Decimal)parms.ReturnValue;

      // Even though the single-run procedure has been deleted on the
      // AppServer, use Dispose( ) to clean up the resources on the client.
      openPO.Dispose( );
      openAO.Dispose( );
    }
  }
}
A singleton procedure can be run in the same way, with ProcedureType.Singleton substituted into the CreatePO method. Unlike a single-run procedure, a singleton procedure remains instantiated on the AppServer after execution, but you still need to use Dispose() to clean up resources on the client side.