Skip to content

JSON Serialization/Deserialization

Overview

JSON is a lightweight data-interchange format that is based on the JavaScript programming language. It is used by many applications and services to encode data into a format that can be easily serialized and transferred between different systems. Nearly all modern programming languages support JSON in one form or another.

This sample demonstrates how to make RESTful service calls that use JSON serialization/deserialization through Neuron. The sample first demonstrates a Windows Communication Foundation (WCF) client calling a Neuron Client Connector utilizing the WebHttp binding. Neuron then routes the request through a Service Connector that calls a WCF service using the WebHttp binding. Both the client and service application utilize the JSON.Net library to serialize/deserialize the message bodies into the JSON format.

This sample utilizes JSON.Net to serialize and deserialize objects for transfer over HTTP. More information about JSON.Net can be found at http://james.newtonking.com/projects/json-net.aspx.

Solution

This sample uses the same Neuron solution as the other five REST samples. The solution contains five processes. This sample utilizes the “JSON Converter” process along with the service endpoint named “JSONServiceEndpoint”.

Running the Sample

Open the Sample

To open this sample, see the topic Using the Neuron Samples and select the REST Client and Service with JSON Encoding sample.

Setup Instructions

Before running this sample, follow these instructions:

Note: To add an assembly to the Global Assembly Cache, run the following command in a Visual Studio Developer Command Prompt as administrator: gacutil -i <Path of Assembly>
  1. Add the assembly Samples\Services\RESTServices\JSON\Newtonsoft.Json.dll to the Global Assembly Cache
  2. Add the assembly Samples\Services\RESTServices\JSON\Customer\bin\Debug\ Neuron.Samples.JSON.Customer.dll to the Global Assembly Cache.
  3. Open the sample solution JSON.sln in Visual Studio. Verify the Newtonsoft.Json assembly is correctly referenced in both the JSONClient and JSONService projects. If not, add a reference to the assembly added to the GAC in step 2.
  4. Build the solution.
Note: This sample does not use the MessageData database. Any errors that occur in the Neuron Event Log relating to the MessageData database should not affect the running of the sample.

Run Instructions

  1. The Samples Launcher opens one Neuron Test Client. Select JSONLogSubscriber from the Party Id dropdown list and click the Connect button. Click on the Receive tab in the test client.
Figure 1: The Neuron Test Client connected as the JSONLogSubscriber party.
  1. In Visual Studio, press F5 to start both the JSONClient and JSONService projects in debug mode.
Figure 2: The JSONClient console window.
  1. In the JSONClient console window, press Enter to start sending messages to Neuron.
Figure 3: The JSONClient console window after running the sample.
  1. As the sample runs, the client sends a message to the service and displays the response. When the client performs a POST operation, a log message is also routed to the Test Client.
Figure 4: The Test Client window after receiving the log message.
  1. When the client completes, press <ENTER> in both the client and service consoles to close the applications.
Was this article helpful?
Dislike 0
Previous: Sending Binary messages via REST