How to create Action<HttpConnectionOptions> for HubConnectionBuilder().WithUrl() RRS feed

  • Question

  • I'm new to C# HubConnectionBuilder and websocket in general. One of its extension methods or overload I want to use is:

    private HubConnection _connection;
    _connection = new HubConnectionBuilder()
                       .WithUrl(uriString, HttpTransportType.WebSockets, actionHttpConnectionOptions).

    My purpose is to add some Headers into the _connection although I am not sure if I am doing it right but I want to add these headers.

    Dictionary<string, string> httpHeaders = new Dictionary<string, string>()
        {"Connection", "Upgrade"},
        {"Upgrade", "websocket"},
        {"Origin", "http://localhost:5256"},
        {"Sec-WebSocket-Version", "13"},
        {"Sec-WebSocket-Key", "dteldf73hdlzfg"},

    I am having difficulty in the part of actionHttpConnectionOptions which has a signature Action<HttpConnectionOptions>.

    How can I accomplish as I am not used in programming with Action or delegate?

    P.S. My ultimate goal is to connect to a websocket server of AWS real-time transcription, so what I'm doing is a client. If I manually connect to the server using command line curl, it returns HTTP/1.1 101 Switching Protocols so that means handshaking and everything has already established. If this everything goes okay with this, a microphone should be connected to the system to send voice messages to the websocket.

    • Edited by pjreu Wednesday, April 15, 2020 12:56 PM Added details.
    • Moved by CoolDadTx Wednesday, April 15, 2020 1:24 PM ASP.NET related
    Wednesday, April 15, 2020 12:45 PM

All replies

  • Please post questions related to SignalR and ASP.NET in the ASP.NET forums.

    Michael Taylor http://www.michaeltaylorp3.net

    Wednesday, April 15, 2020 1:24 PM