Getting a bit technical: JSON, REST and WCF

This time I decided to get a bit technical to cover some stuff I am currently learning and researching about, and that I think might be of some help for someone who is getting in touch with these subjects for the first time.

There are many technologies out there, but this article covers the basics, starting with JSON, a lightweight format for data interchange between systems; REST, a standard to create web services; and WFC, a framework to create service-oriented applications using Microsoft technology.

Background

From the moment that the Interner allowed the interaction of a massive base of users on, the creation and expansion of decentralized services to attend them began.

The goal was to build decoupled state-less systems, that were asynchronous and programing language agnostic at the same time, that led to what is, roughly, the genesis of what is known today as web services.

JSON

What is it?

JSON is the acronym for JavaScript Object Notation, a programming language-independent data interchange format. It is human-readable, easy to write and easy for computers to understand. The European Computer Manufacturer’s Association (ECMA) introduced it the ECMA-404 standard.

Its syntax uses curly brackets, square parenthesis, colon and semicolon so that it allows data to be organized with attributes and their respective values. The literal object definition stated on ECMAScript inspired such syntax.

What is it used for?

It is mainly used to transmit data between servers and web and mobile applications. Moreover, its creation responds to the necessity of transferring stateless objects between systems.

Data types

JSON admits the universal data types: string, number, boolean, null, array, and objects.

Structure

Like it can be observed in the previous examples, JSON is composed of two structure types:

The following is an expanded example of the structure used to compose a more complex JSON object:

REST

What is it?

REST stands for Representational State Transfer and must not be confused with web service or with RESTful API. It can be seen as a standard, a concept or an architecture that defines how the communication between computer systems must be structured because it aims at separating the client and the server layers.

REST by definition is stateless, so both, client and server, are unaware of their states.

The communication under the REST standard takes place using JSON.

How is it used?

Under the REST paradigm, a client requests something to a server by sending a message, which is responded with another message.

The aforementioned RESTful API is used to accomplish this, which is nothing more than an interface implementation based on REST.

A request consists of a call to a REST verb or method, a header that specifies information about the request, a route to a resource on the server, and an optional message body that contains the data or the representation of the JSON object.

REST methods and their relation with CRUD

The methods or verbs available in REST to handle and transmit information are the following:

The relationship between the REST and CRUD methods can are as follows:

WFC

What is it?

Windows Communications Foundation is a framework created by Microsoft to build service-oriented applications.

It allows the transmission of messages from one end-point to another between client and server in an asynchronous way. To achieve this, it offers three different ways: with a response, without response (one-way), and duplex, where both parties end-points are transmitter and receptor at the same time (or transceivers, to be more accurate).

An interesting feature that it has is that they can operate through multiple messaging channels or transport protocols, as well as different encodings. All this means that the same service can handle queries through HTTP, HTTPS, TCP and named pipes, and what is even more convenient, each transport method can be activated just by editing configuration files, that is, without touching the code.

It usually uses encoded messages that comply with the SOAP protocol, but they can also use JSON.

The architecture that WCF uses is the following:

Source: https://docs.microsoft.com/en-us/dotnet/framework/wcf/architecture

How is it used?

Bindings specify how a Windows Communication Foundation (WCF) service endpoint communicates with other endpoints. At its most basic, a binding must specify the transport (for example, HTTP or TCP) to use. You can also set other characteristics, such as security and transaction support, through bindings.”

System-provided bindings:

• BasicHttpBinding
• WSHttpBinding
• WSDualHttpBinding
• WSFederationHttpBinding
• NetHttpBinding
• NetHttpsBinding
• NetTcpBinding
• NetNamedPipeBinding
• NetMsmqBinding
• NetPeerTcpBinding
• MsmqIntegrationBinding
• BasicHttpContextBinding
• NetTcpContextBinding
• WebHttpBinding
• WSHttpContextBinding
• UdpBinding

The following is an example that uses the BasicHttpBinding class for a simple calculator API service using .NET 4.6.1:

Conclusion: Getting non-technical

The advent of the web has caused a change in paradigms, especially with the introduction of Hardware-As-A-Service (HaaS) and Cloud Computing, that have forced the industries to aim at decoupling the systems to decrease costs by reaching economies of scale, creating cross-platform software, distributing workload, achieving scalability, maintainability, to mention some.

What many might have unforeseen with the introduction and expansion of APIs, was the arrival of new business opportunities. Moreover, this would be arguably one of the best things regarding technology: it’s not all about the technology itself, but what you can do with it.

Today we have APIs that can help technologically solve most of the business problems. For example, you can find APIs for handle maps, digital assets management, processing and storage, telephony and text messaging, team and project management, natural language processing and text-to-speech, to mention some.

Just imagine what problems you can solve with these technologies. The sky is the limit.