WebSocket Registration
Tutorial Source Code

.NET/C#

Example: 4.1.01-WebSocket-Register

Last Update Sept 2021
.NET/C# Requirements See Getting Started with .NET.
Pre-requisites

Enable the session environment as outlined within the Getting Started guide.

To build and run the above example:

  1. Right-click the specific project and choose "Set As Startup Project"
  2. From the Visual Studio menu, choose "Build - Build Solution"
  3. Once built, run the example by hitting (Ctrl+F5).


Overview

Whether accessing from the desktop, directly to the cloud, or through your deployed managed streaming services, the Refinitiv Data Libraries provide ease-of-use interfaces to retrieve real-time streaming content from the platform.  The Refinitiv Data Library for .Net interfaces with Refinitiv's streaming services based on popular .Net WebSocket implementations and supports the option for developers to choose an alternative WebSocket implementation through a simple registration interface.  By default, the Refinitiv Data Library for .Net utilizes Microsofts' ClientWebSocket implementation.

The following tutorial will outline sample code that enables users to register an alternative .Net Websocket implementation within the library.

WebSocket Implementations

The Refinitiv Data Library for .Net project includes a number of WebSocket implementations that can be directly installed within your projects.  The following NuGet packages are available:

Built on top of the WebSocket.client implementation, this package is a wrapper over Microsofts' native C# class ClientWebSocket.

Built on top of the Ninja.WebSockets implementation, this package is a concrete implementation of the .Net Standard 2.0 System.Net.WebSockets.WebSocket abstract class.

Built on top of the WebSocket4Net implementation, this package originated from the SuperWebSocket WebSocket Client.

Built on top of the WebSocketSharp-netstandard implementation, this package is an extension of the WebSocketSharp, enabling .Net Core developers to build and run against newer releases of the .Net environment.

How to register an alternative WebSocket package

To override the default WebSocket implementation within the library, developers can download and install any of the available implementations (NuGet) of their choice.  The library provides a registration mechanism, via Extension Methods, that will allow the ability to select the specific WebSocket implementation once the NuGet package has been installed within your project.

For example, the tutorial source code project has installed 2 WebSocket implementations, NinjaWebSockets and WebSocket4Net, to demonstrate registration.  Once installed, the library exposes the following registration interface:

The above screenshot shows the IntelliSense interface displaying the installed WebSocket implementations.  In addition to the 2 NuGet installations, you can also see the default ClientWebSocket implementation.

Note: To ensure proper registration, it's important to perform this step prior to creating a session within the platform.  Refer to the source code example.

Executing the Application

The example application was designed to stream real-time market data quotes from the platform based on a selected WebSocket implementation.

Within the source code package, select the source code example within the 4. Misc section.  To execute the example, refer to the pre-requisites section at the top of this tutorial.

The expected output should look similar to this:

Selecting any of the available implementations will yield the same result.  If you noticed, a 3rd option is available, i.e. the default ClientWebSocket implementation.  To verify the library did in fact utilize the selected implementation, you can refer to the logs.  For example, within the binary directory, review the file RDPLog_<pid>.log and you will see output similar to this:

    	
            

...

2021-09-09 21:05:47.5439|Info|Refinitiv.Data.Core.PlatformSessionCore|7|PlatformSession (Cloud) Session State transitioned from Pending to Opened

2021-09-09 21:05:47.5735|Info|Refinitiv.Data.Delivery.Stream.RDPWebSocket|1|Created IWebSocket Interface: Ninja WebSockets

2021-09-09 21:05:47.5735|Info|Refinitiv.Data.Delivery.Stream.OMMConnection|1|Streaming Connection initiated using:

Host: amer-3-t3.streaming-pricing-api.refinitiv.com

...