Develop and use a windows service with Dynamics CRM

As mentioned in a separate post, when dealing with complex logic in Dynamics CRM, the right way to go is to isolate the complex part of your functionality in a separate windows service and consume it from your CRM.  In this article I will present the overall implementation guidelines / architecture of this approach.

As the first thing, let’s assume an use case. We want to implement a booking system with Dynamics CRM, and one of the core functionalities is calculating the booking price, that hides a complicated logic behind the scenes. Developing this with a plugin is cumbersome as the calculation routine can depend on many parameters and might always be a subject of changes, as you will often have to enhance your algorithm.

Now let’s build the implementation plan! (Please note that just the big pieces are presented. The details will follow)

  1. Create a C# Library that would implement the complex logic, and specifically, the function
    public static decimal CalculatePrice(string resource)
     decimal price = 125.50m;
     // Implement your logic
     return price;
  2. Create a Web API method to provide access to the business logic:
    public class BookingController : ApiController
     public IHttpActionResult CalculatePrice(string resource)
     decimal price = Booking.CalculatePrice(resource);
     return Json( price );
  3. Create a javascript resource to call the Web API method
    function CalculatePrice(resource) {
     $.get("https://localhost:9876/api/Booking/CalculatePrice?resource=xyz", function (data) {
     $("#price").html("The calculated price is:" + data + " EUR");
  4. Create an HTML resource that will call the javascript and display the result:
    <meta charset="utf-8" />
    <script src="Booking.js"></script>
    <script src=""></script>
    <input type="button" id="calculate-btn" onclick="CalculatePrice()" value="Calculate Price" />
    <div id="price">.....</div>

As a bonus, here is a nice image for you:


Leave a Reply

Your email address will not be published. Required fields are marked *