where Business Processes, Data and Rules meet.
Blog
Home / Business Rule / .NET Decision as a Service – REST API Client for .Net

.NET Decision as a Service – REST API Client for .Net

1

This .NET Decision as a Service client library is an SDK for .NET applications to communicate with the Decision as a Service platform easily. This is very similar to the client library in Javascript as shown in a previous post.
As we discussed earlier, using a Decision as a Service platform allows you to simply share the decision module as REST API service. Remember, a decision module may have one or multiple different types of a business logic (i.e., Decision Table, decision flow, Decision Model and Notation (DMN), etc.)

Setup

Once you have installed the decision server, you will notice it comes with two client libraries. One is for Javascript clients and the other is for .Net applications.

In your application use NuGet and install the following two components:
1. Json.Net (from Newtonsoft.Json)
2. Microsoft.AspNet.WebAPi.Client

Client library

And finally, from where your server is installed, find FlexRule.Server.ClientLibrary and reference it into your project. This library provides a REST API Client for the Business Rule Server (Decision as a Service) out-of-the-box.

The rest is pretty similar to the Javascript library, so let’s now create a simple form as shown below:

CarInsurance-REST-Library-dotnet

And on click event handler of your form just paste the code below:

ExecutionClient.Configuration.MasterServerAddress = "http://192.168.3.11:9000";
var token = ExecutionClient.AcquireToken("app1", "12345678901234567890123456789012");

var response = ExecutionClient.Run(new ExecutionRequest()
{
    // Authentication token
    Token = token,

    // A correlation identifier for the request, so you know what requests were made for what reason
    // This can be deleted if you don't want to track requests.
    CorrelationId = "12345",

    // values for input parameters of decision
    Inputs = new Dictionary()
    {
        {"car", GetCar()}
    },

    // Address of decision for execution
    Service = "Calculator",
    PackageVersion = "1",
    PackageName = "Car Insurance"

    // strategy to select a service within a package
    UseLatestVersion = true,

});

if (!response.IsError)
{
    var result = response.GetValue("car");
    UpdateView(result);
}
else
{
    MessageBox.Show(string.Format("Error {0}: {1}", response.MessageId, response.ErrorMessage));
}

By doing this, your application now connects to the server and returns the result back at the click of a button.

The source code for this application will also be installed on your system when you download and install FlexRule Server.

Read More

  1. .NET Decision as a Service – REST API Client for .Net
  2. JavaScript Decision as a Service – REST API Client for HTML/JS
Recommended Posts

Comments

pingbacks / trackbacks

  • […] In the above model those two questions are in the left top corner. Decision as a Service platform allows you to host the entire above decision model (decision module) as a REST service. Then this business decision can be shared across all processes and applications in different technologies (i.e. JavaScript, .Net Framework…) […]

Leave a Comment

You must be logged in to post a comment
Contact Us

We're not around right now. But you can send us an email and we'll get back to you, asap.