1. Home
  2. FlexRule Runtime (SDK)
  3. Integration
  4. Execute a Model Using RuntimeEngine

Execute a Model Using RuntimeEngine

◷ Reading Time: 2 minutes

If you want to execute a FlexRule model using the FlexRule RuntimeEngine follow the steps mentioned below.

First of all, you need to request the FlexRule Runtime License from FlexRule’s online licensing service using your access token.

1. Get your access token from authentication

var result = AuthService.Auth(input.Email, input.Password);


The access token can be retrieved from the result object.

    2. Generate a machine id

    var user = UserInfo.ExtractUser(accessToken);
    var machineIdGen = new MachineIdGen();
    var machineId = machineIdGen.Generate(new PortalUser
    {
        Login = user.Login,
        Email = user.Email,
        FirstName = user.FirstName,
        LastName = user.LastName
    });

    3. Retrieve the license from the FlexRule Subscription service

    SubscriptionService.RetrieveLicenses(
        accessToken,
        machineId,
        new[] { VersionUtility.Major },
        out var offlineLicense,
        out var forceAuth,
        out var licenses
    );

    4. Extract the FRE license content

    var freLicense = licenses.FRE;

    AuthService and SubscriptionService can be used from the NuGet package. 
    FlexRule.Common.10.1.972.nupkg (Please see the attached file)

    Read this article for more details.

    UserLicense.Key = freLicense;

    Example

    Here is a simple test case to give you an idea of how to use this freLicense and run a model.

    public void test_simple_project()
    {
    //Add your license key here
    UserLicense.Key = freLicense;
    var baseFolderPath = Path.GetFullPath(GetPath("TestProjectName"));
    var workspace = $"workspace-{Guid.NewGuid()}";
    var modulePath = Path.Combine(baseFolderPath, "DecisionGraph.xml");
    var xmlText = File.ReadAllText(modulePath);
    var xmlBytes = Encoding.UTF8.GetBytes(xmlText);
    var runtime = RuntimeEngine.FromXml(xmlBytes, baseFolderPath );
    var js = Json.Parse(@"{}");
    var dic = (IDictionary<string, object>)js;
    var result = runtime.Run(dic);
    }
    Updated on October 28, 2025

    Article Attachments

    Was this article helpful?

    Related Articles