Posts

Showing posts from February, 2022

How to Create a Simple Node JS Webserver serving HTML pages using EJS

Image
  Creating a Web server with Node JS is fairly simple with Node JS which serves HTML view pages. For this purpose I am going to use Visual Studio to create Node JS Web Application type project.  If you are not able to find the template project for Node JS then most likely the packages for Node JS development are not installed from Visual Studio Installer. Installing Node JS Development Tools From the Visual Studio Installer select the Node js development tools and install them to create a Node js project as shown in the figure below. Once its installed we can go ahead and create a empty Node JS web application. Required npm packages for this application would be  http express ejs-locals Server Application is the express App and since its a web application we need to use the http package to host the Application. ejs-locals is a package stands for Embedded javascript Template pack using which we will be able to create html views using javascript. Install the required p...

How to achieve Duplex Communication in WCF using Duplex Contract in C#

Image
  Most of us are aware of how to use WCF to call server side API from client, but there is also a way to call client side API's from the Server. This is possible with the use of Duplex contract in WCF. With the help of duplex contract we will be able to achieve duplex communication. In this post we will be seeing how to accomplish this with the help of an example. How to Define Duplex Contract in WCF? To define the capabilities of a service we define what is called as a Service Contract which is also used for creating the proxies at the client side. While defining the Service contract there is a parameter called CallbackContract which takes in a type of Interface which is used to define the client side API's. In the above example we have defined a Service Contract with a Callback Contract of type IStateChangeCallback which is an interface which exposes the API's which can be defined at the client side. In a normal WCF service we would not define the Callback contract. Serv...

How to Customize the API variant generated for the added WCF Service Reference

Image
  We must have seen that when we try to add a WCF service reference in a client project two different versions of the API's in the service is generated. One is the Synchronous variant and the other one is the Asynchronous variant of the same method in the Service that we are referring to. Before going to how we can customize the API generated, let us discuss about the need of Asynchronous service API.  Why do we need to have Asynchronous API variant?  Asynchronous Service API's allows us to do CPU intensive operation/operation which takes lots of time such as database query etc. in a separate thread so that the application's Main thread will be freed and the application will not freeze. Choosing the type of API variant in the Client Side We can choose to generate the API variant that we require through Service Reference Settings in the client side. For that Open the Service Reference Dialog by clicking on the Reference->Add Service Reference. Once the Service Refe...

How to Add HTML Elements into DOM through JavaScript Code

Image
  We all might have encountered the case where we need to insert the HTML elements through JavaScript code as part of some event handling. This is called as dynamic addition of UI Controls from the code. Significance of DOM(Document Object Model) In JavaScript world its relatively easy to add any html control to the DOM (Document Object Model). For the control to be visible in the UI it has to be added to the DOM. We will see now an example of how this can be done. This requires some basic understanding of the HTML and the JavaScript. Lets see the existing HTML DOM structure where we would try to insert a custom element. As shown above we have a div block which is labelled as "chat-messages". We will try to insert the custom html code into this block as shown in the figure below: As shown in the figure above we have defined a function showMessagesInChat whose responsibility is to insert HTML code into the chat-messages div block. In the first line of the JavaScript code ...

Different Ways to Send Message Using Sockets to another Process - An example from Node Application

Image
Introduction  We all are aware that to develop complex application the best way to design it is to create loosely coupled modular designs with distributed logic. This way it will be more Scalable and maintainable in the future. Often in those scenarios there is a need to communicate between different processes running in the application to proceed with its operation. There are various IPC(Inter Process Communication) mechanisms that are there to accomplish this like use of shared memory, using pipes etc. What we are going to discuss here is about sockets which are web based to communicate between different processes. The advantage of using Sockets are they enable two way communication between processes and its event based. Example of Socket Programming We will see an example from the Node application how this is done, mainly we will be concentrating on the different ways or types of firing message using sockets. As you can see in the example above from Node js server code we will b...

What is PRISM ? Why its preferred UI framework in .NET for Desktop Based Application?

Introduction Most of us who are from software development background especially in User Interface might have already heard about the .NET UI framework known as PRISM. Its a well accepted framework to develop scalable and complex desktop based application using .NET technology. Its an Open Source Framework to develop complex application consisting of different UI components which in themselves are pretty complex. PRISM is based on MVVM(Model View View Model) pattern which is used in WPF to separate the View Logic from the business logic. PRISM helps in providing a template to design and develop User Interface in WPF. Suggested Read :  Load Data Asynchronously in WPF What is PRISM? PRISM is available in both .NET Framework as well as .NET Core. To develop application using PRISM one has to be familiar with the Microsoft Windows Presentation Foundation(WPF). The main features of PRISM are as follows: Divides the UI into different Regions which are independent from each other...