How to use .NET WebSocket Client with NTLM proxies?
Asked Answered
I

1

11

My goal is to use a WebSocket .Net client implementation (i.e. not a browser) to connect to a WebSocket over a corporate proxy that requires NTLM authentication. So far, all the solutions (e.g. websocket-sharp-with-proxy, websocket4net) come up short.

I have tried these:

How to use proxies with the WebSocket4Net library

https://mcmap.net/q/303677/-is-there-a-websocket-client-implemented-for-net-closed

As far as I know, the author has not updated this discussion on adding NTLM proxy support. http://websocket4net.codeplex.com/discussions/448172

This question tried to ask why client implementations do not support proxies, but it was not answered, and did not shed any new light on why nobody wants to approach the problem.

So back to my question, how does one use WebSocket technology in a client app behind an NTLM proxy?

Illustrate answered 23/8, 2016 at 3:22 Comment(4)
what are you using for the underlying .NET http stack? Most windows stacks (e.g. WinInet, WinHTTP) will already support NTLM.Kicksorter
@Kicksorter Something to the tune of new WebSocket("ws://echo.websocket.org", origin: "http://example.com"); but that doesn't take an NTLM proxy as a parameter. The libraries I mentioned were also tried, and whatever they use internallyIllustrate
Could you mention if this is like a standalone service process or more like a desktop app that a person would be logged in and starting your app from their credentials?Ruiz
A desktop app (portable, xcopy-like)Illustrate
D
3

The ClientWebSocket object found in System.Net.WebSockets contains an Options property which allows you to configure proxy settings.

var ws = new System.Net.WebSockets.ClientWebSocket();
await ws.ConnectAsync(new Uri("destination.com"), CancellationToken.None);
ws.Options.Proxy = new WebProxy("example.com")
{
    Credentials = new NetworkCredential("userName", "password")
};

The NetworkCredential object is used for password based authentication and may provide what you need. You can also try setting Credentials on the Options property of the WebSocket object like this if the above doesn't work.

ws.Options.Credentials = new NetworkCredential("userName", "password");

I do not have access to this type of environment, so I have not actually tried what you are trying to do and am not sure if this will help. But, this looks like it will work to me.

Diwan answered 7/9, 2016 at 22:27 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.