georgekosmidis / AspNetCore.WebSockets

A WebSocket sample for AspNetCore, using Azure DevOps, Docker, Azure Container Registry and Azure App Service

Home Page:http://aspnetcore-websockets.azurewebsites.net/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

DotNetCore.WebSockets

This is a sample on how to work with .NET Core and WebSockets. The sample is about a software licensing process, where the end customer submits a license request to a RESTful API via POST, and retrieves it via GET. The License is signed by a 3rd party software that connects to the current solution via WebSockets. When connected, the solution sends the License Request and receives it back signed.

Features

  • RESTful API
    • Accepting POST requests with a LicenseRequestModel. As per REST principles, returns a LicenseResponseModel) and a Location header to retrieve the resource.
    • Accepting GET requests for the newly created resource that returns a LicenseResponseModel, which contains (or not yet) the Signed License.
    • The state of the License (signed or not yet) is singaled with the property Status.
  • WebSocket
    • A middleware (LicenseSignatureGeneratorMiddleware) is handling WebSocket connections.
    • A queue is used to send License Requests, one by one, when the WebSocket client (a hypothetical LicenseSignatureGenerator engine) is connected.
    • The WebSocket middlware is dequeueing a message to send and upon receiving a valid message it's storing in using a storage service.
    • The WebSocket messages are exchanged with a LicenseMessage model.
    • Allowed Origins is in AppSettings (currently allowing all).
  • Testing
  • Azure
  • Sample Page (index.html)
    • Left column is an end customer sending a License Request (fields are prefilled with data)
    • Right column is the 3rd party app (a License Signature App) waiting to connect to the WebSocket
    • Usage
      • Click 'Submit Data' on the left (only one initially). Long polling starts (every 3 secs), waiting for a signature (Status: 30).
      • Click 'Connect' on the right. Upon connecting retrieves all messages awaiting.
      • Click 'Send' on the right (a signed license is already prefilled).
      • Long polling stops, signature arrived.

About

A WebSocket sample for AspNetCore, using Azure DevOps, Docker, Azure Container Registry and Azure App Service

http://aspnetcore-websockets.azurewebsites.net/

License:MIT License


Languages

Language:C# 66.2%Language:HTML 32.7%Language:Dockerfile 1.1%