Native C# Client for Web Sockets

cghersi
cghersi Member Posts: 1
edited March 2022 in PubSub+ Event Broker #1

Hi all!

I need to connect via WebSockets to an on-prem Solace Broker from my native app (UWP written in C#).

I also need to add I the Connect() HTTP request a specific HTTP Header "Authorization" with a Bearer token that I generate in the app.

I cannot see a way to configure the Solace C# SDK to perform such a custom activity, so first of all, do you know any way to do this with the Solace SDK?

Alternatively, I could write a simple native WebSocket without using the Solace SDK, but I need the parameters to connect.

E.g. I tried using a very simple approach (using a NuGet package https://github.com/PingmanTools/websocket-sharp/) like this:

using WebSocketSharp;
WebSocket ws = new WebSocket("wss://mr-bqdpohy3bis.messaging.solace.cloud:443");  
ws.SetCredentials("solace-cloud-client", "<myPsw>", true); 
ws.Connect();

but it doesn't work...

What am I missing?

Thanks!!

cghersi

Tagged:

Answers

  • Ragnar
    Ragnar Member, Employee Posts: 65 Solace Employee

    Hi,

    Why do you have a need to set the bearer token? The web-socket connection is between your client and the broker and the broker has no requirement for a bearer token? You authenticate with the broker via usename/password (as in your websocket only sample), or with kerberos token, or with x.509 client certificate. The latest APIs and broker also support OAUTH2.0. In all of these case the authentication parameters can be supplied as properties on session create.

    Regards,

    Ragnar