Using CRM from an external website – part 5: Stage two “Client side scripting”

In this series I’m working towards a scenario in which I integrate Dynamics CRM with an external web site. My ultimate goal is to run an external web site on a non Microsoft platform, using web technologies to communicate with Dynamics CRM. Before I get to that point, I have to jump through some hoops.

In stage one I trusted on a Microsoft Internet Information Server hosting a Web API controller written in C#.
The Web API controller was called from client side javascript embedded in the HTML page. In stage two we take it to the next level. Instead of using a Web API Controller written in C#, we build a model and logic in javascript.

In this stage we still trust on Microsoft Infrastructure in order to authenticate ourselves. The idea is that the context of the user logged in, is used to call the web services on Dynamics CRM.

How does this work?


The user is logged in to the company network. Whenever he (or she) opens the browser and calls a web page, the credentials of the user are sent with the call. Internet Information Server responds to the call and serves the requested web page. The web page is processed in the browser of the user, scripts are executed.

One of the scripts calls a web service on Dynamics CRM. The credentials of the user are sent as well to the Dynamics web service. Dynamics CRM uses the incoming credentials to validate if the user is authenticated to use CRM. In case the user is authenticated, the web service is executed (in case the user is authorized to access the data). The results are passed back to the calling browser.

In this scenario (scenario two) I completely depend on the infrastructure to handle the authentication and authorization. This will work if we are running inside a domain, having a Dynamics CRM server and an Internet Information Server in this domain as well.

What am I going to build?

The design pattern that I’m going to use it the MVVM pattern. What I’m going to build is a viewmodel in javascript. This viewmodel is going to be bound to the webpage using the Knockout framework. The viewmodel is going to contain a representation of the entity that I’m going to expose.
The viewmodel itself will get methods to insert, update, delete and select data. The interaction between the viewmodel and Dynamics CRM will be implemented using REST calls (post, get).

The main reasons I’m going to use the Knockout framework are:

  • it’s free
  • it’s easy to learn
  • lightweight
  • does not depend on other frameworks
  • supported by almost any browser (version) out there
  • kick ass tutorials
  • wide spread

However, there a a number of other cool frameworks out there, like e.g. Aurelia. Aurelia is the new kid on the block and promises even to be easier than Knockout. Personally I don’t have experience with this framework but I hear some very positive sounds about it.

In the next article, I’m going to build the demo for scenario two.

Stay tuned, It will take me a couple of days.