WSClientGWrapper 1.0.0

The owner has unlisted this package. This could mean that the package is deprecated, has security vulnerabilities or shouldn't be used anymore.
dotnet add package WSClientGWrapper --version 1.0.0
                    
NuGet\Install-Package WSClientGWrapper -Version 1.0.0
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="WSClientGWrapper" Version="1.0.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="WSClientGWrapper" Version="1.0.0" />
                    
Directory.Packages.props
<PackageReference Include="WSClientGWrapper" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add WSClientGWrapper --version 1.0.0
                    
#r "nuget: WSClientGWrapper, 1.0.0"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package WSClientGWrapper@1.0.0
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=WSClientGWrapper&version=1.0.0
                    
Install as a Cake Addin
#tool nuget:?package=WSClientGWrapper&version=1.0.0
                    
Install as a Cake Tool

WebSocket Client Generic Wrapper (WSClientGWrapper)

Implementation of a generic wrapper for the Microsoft ClientWebSocket class (.NET Core)

How to use it?

  • The class WSClientGWrapper<TSend, TResponse> is the main definition of the generic wrapper, where the TSend is the type of data to be sended, and the TResponse is the type of the data that will be received.
  • To use the string type to send/receive data, you can use the SimpleWebSocketClientWrapper class.

Steps :

  1. Instantiate a new wrapper object by choosing one of the two options mentioned above. e.g.
    var wrapper = new WSClientGWrapper<string, string>("wss://api.com/customers");
    
    **P.S 😗*
    • The 2nd argument in the constructor fixRemoteCertValidation by default false, is used to enable/disable remote certificate validation.

      • For WebSocket secure connection wss:// we need to validate certificate, but in some cases we're gone be using self-signed certificate, and it gaves errors on connecting the WebSocket (validation errors), to skip validation set the 2nd parameter value to true.
    • [Optional] Now we have our wrapper object we need to set the response converter callback :

      • What is this callback ?
        • This callback is used to convert the response data from byte[] to TResponse, but we need to define how the data will be converted, by default the data is converted to string data type by using :
          Convert.ChangeType(Encoding.UTF8.GetString(bytesData), ...);
          
  2. Now we need to define all needed callbacks :
    • OnConnect :

      • To be called on the WebSocket connection.
      • Generally here where you need to add initialization calls (wrapper.SendMessage(...)).
      • returns the current wrapper.
    • OnDisconnect :

      • To be called on the WebSocket disconnection.
      • returns the current wrapper.
    • OnMessage :

      • To be called on message arrival.
      • Receives in argument the WSClientGWrapperArgs :
        • This class contains :
          • Data : the message payload.
          • Endpoint : the current URI where the WebSocket is connected to it.\
          • Wrapper : is the current wrapper object.
    • OnError :

      • To be called on any error encountered.
      • Receives in argument the WSClientGWrapperErrorArgs :
        • This class contains :
          • Message : the error message.
          • Endpoint : the current URI where the WebSocket is connected to it.\
          • Wrapper : is the current wrapper object.
  3. Now we need to connect the WebSocket and start listening by calling the connect method :
    wrapper.Connect();
    
If you need to change the WebSocket URI without connecting the socket, use the RebuildClient(string baseAddress, bool fixRemoteCertValidation = false)
If you need to change the WebSocket URI and create a new connection, call the RebuildClientAndConnect(string baseAddress, bool fixRemoteCertValidation = false).

Disconnect the WebSocket :

  • To disconnect the client, use the disconnect method.
Product Compatible and additional computed target framework versions.
.NET net6.0 is compatible.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • net6.0

    • No dependencies.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated