Created
January 24, 2021 13:08
-
-
Save fzankl/8dfb2bd69c834a8139250ed5dc5b1db5 to your computer and use it in GitHub Desktop.
Creating a websocket connection to Azure IoT Hub device streams
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public async Task<ClientWebSocket> CreateAsync( | |
Uri url, string authorizationToken, | |
CancellationToken cancellationToken) | |
{ | |
var webSocketClient = new ClientWebSocket(); | |
webSocketClient | |
.Options | |
.SetRequestHeader( | |
"Authorization", | |
$"Bearer {authorizationToken}"); | |
await webSocketClient.ConnectAsync( | |
url, | |
cancellationToken).ConfigureAwait(false); | |
return webSocketClient; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment